-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Expo Web out of the box! #1686
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
boilerplate/app/components/auto-image/auto-image.story.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable */ | ||
import * as React from "react" | ||
import { storiesOf } from "@storybook/react-native" | ||
import { StoryScreen, Story, UseCase } from "../../../storybook/views" | ||
import { AutoImage } from "./auto-image" | ||
|
||
declare let module | ||
|
||
const bowser = require("../../screens/welcome/bowser.png") | ||
const morty = { uri: "https://rickandmortyapi.com/api/character/avatar/2.jpeg" } | ||
|
||
storiesOf("AutoImage", module) | ||
.addDecorator((fn) => <StoryScreen>{fn()}</StoryScreen>) | ||
.add("Style Presets", () => ( | ||
<Story> | ||
<UseCase text="With require()"> | ||
<AutoImage source={bowser} /> | ||
<AutoImage source={bowser} style={{ width: 150 }} /> | ||
<AutoImage source={bowser} style={{ width: 150, height: 150 }} /> | ||
<AutoImage source={bowser} style={{ height: 150 }} /> | ||
<AutoImage source={bowser} style={{ height: 150, resizeMode: "contain" }} /> | ||
</UseCase> | ||
<UseCase text="With URL"> | ||
<AutoImage source={morty} /> | ||
<AutoImage source={morty} style={{ width: 150 }} /> | ||
<AutoImage source={morty} style={{ width: 150, height: 150 }} /> | ||
<AutoImage source={morty} style={{ height: 150 }} /> | ||
<AutoImage source={morty} style={{ height: 150, resizeMode: "contain" }} /> | ||
</UseCase> | ||
</Story> | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useLayoutEffect, useState } from "react" | ||
import { | ||
Image as RNImage, | ||
ImageProps as DefaultImageProps, | ||
ImageURISource, | ||
Platform, | ||
} from "react-native" | ||
|
||
type ImageProps = DefaultImageProps & { | ||
source: ImageURISource | ||
} | ||
|
||
export function AutoImage(props: ImageProps) { | ||
const [imageSize, setImageSize] = useState({ width: 0, height: 0 }) | ||
|
||
useLayoutEffect(() => { | ||
if (props.source?.uri) { | ||
RNImage.getSize(props.source.uri as any, (width, height) => { | ||
setImageSize({ width, height }) | ||
}) | ||
} else if (Platform.OS === "web") { | ||
// web requires a different method to get it's size | ||
RNImage.getSize(props.source as any, (width, height) => { | ||
setImageSize({ width, height }) | ||
}) | ||
} else { | ||
const { width, height } = RNImage.resolveAssetSource(props.source) | ||
setImageSize({ width, height }) | ||
} | ||
}, []) | ||
|
||
return <RNImage {...props} style={[imageSize, props.style]} /> | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Reactotron from "reactotron-react-native" | ||
export const Tron = Reactotron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Reactotron from "reactotron-react-js" | ||
export const Tron = Reactotron |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
presets: ["babel-preset-expo"], | ||
env: { | ||
production: {}, | ||
}, | ||
plugins: [ | ||
[ | ||
"@babel/plugin-proposal-decorators", | ||
{ | ||
legacy: true, | ||
}, | ||
], | ||
["@babel/plugin-proposal-optional-catch-binding"], | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This is the first file that ReactNative will run when it starts up. | ||
import App from "./app/app.tsx" | ||
import { registerRootComponent } from "expo" | ||
|
||
registerRootComponent(App) | ||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that React Native Web is considering a new API for the Image component, which may help us here. But in the meantime, this will do nicely.
necolas/react-native-web#1786