-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support expo image * update yarn lock * remove duplicate style of expo image * update example
- Loading branch information
Showing
7 changed files
with
254 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import * as React from "react"; | ||
import { View, StyleSheet, Text } from "react-native"; | ||
import { ExpoImage, withTheme } from "@draftbit/ui"; | ||
import Section, { Container } from "./Section"; | ||
|
||
interface WrapperProps { | ||
label: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
const Wrapper: React.FC<WrapperProps> = ({ label, children }) => { | ||
return ( | ||
<View style={styles.wrapper}> | ||
<View style={styles.boxLabel}> | ||
<Text>{label}</Text> | ||
</View> | ||
<View>{children}</View> | ||
</View> | ||
); | ||
}; | ||
|
||
const ExpoImageExample: React.FC = () => { | ||
return ( | ||
<Container style={{}}> | ||
<Section title="Image Examples" style={{}}> | ||
<View style={{ flexDirection: "row" }}> | ||
<Wrapper label="Basic remote image"> | ||
<ExpoImage | ||
source={{ | ||
uri: "https://picsum.photos/1100", | ||
}} | ||
style={{ | ||
width: 200, | ||
height: 200, | ||
}} | ||
/> | ||
</Wrapper> | ||
<Wrapper label="Local image"> | ||
<ExpoImage | ||
source={require("./assets/images/hamburger.png")} | ||
style={{ | ||
width: 200, | ||
height: 200, | ||
}} | ||
/> | ||
</Wrapper> | ||
</View> | ||
<View style={{ flexDirection: "row" }}> | ||
<Wrapper label="Content fit: contain"> | ||
<ExpoImage | ||
source={{ | ||
uri: "https://picsum.photos/1300", | ||
}} | ||
contentFit="contain" | ||
style={{ | ||
width: 200, | ||
height: 200, | ||
backgroundColor: "#f0f0f0", | ||
}} | ||
/> | ||
</Wrapper> | ||
<Wrapper label="With blur hash"> | ||
<ExpoImage | ||
source={{ | ||
uri: "https://picsum.photos/seed/696/3000/2000", | ||
}} | ||
blurhash="LEHLk~WB2yk8pyo0adR*.7kCMdnj" | ||
transition={5000} | ||
style={{ | ||
width: 200, | ||
height: 200, | ||
}} | ||
/> | ||
</Wrapper> | ||
</View> | ||
</Section> | ||
<Section title="SVG Image" style={styles.wrapper}> | ||
<Wrapper label="Remote SVG Image"> | ||
<ExpoImage | ||
source={{ | ||
uri: "https://upload.wikimedia.org/wikipedia/commons/3/30/Vector-based_example.svg", | ||
}} | ||
style={{ | ||
width: 200, | ||
height: 200, | ||
}} | ||
/> | ||
</Wrapper> | ||
<Wrapper label="Local SVG Image"> | ||
<ExpoImage | ||
source={require("./assets/images/example.svg")} | ||
style={{ | ||
width: 200, | ||
height: 200, | ||
}} | ||
/> | ||
</Wrapper> | ||
</Section> | ||
<Section title="Transition Effects" style={{}}> | ||
<View style={{ flexDirection: "row", flexWrap: "wrap" }}> | ||
<Wrapper label="Cross Dissolve - Ease In Out"> | ||
<ExpoImage | ||
source={{ uri: "https://picsum.photos/1400" }} | ||
transitionDuration={3000} | ||
transitionEffect="cross-dissolve" | ||
transitionTiming="ease-in-out" | ||
style={{ width: 200, height: 200 }} | ||
/> | ||
</Wrapper> | ||
<Wrapper label="Flip from Top - Ease Out"> | ||
<ExpoImage | ||
source={{ uri: "https://picsum.photos/1500" }} | ||
transitionDuration={3000} | ||
transitionEffect="flip-from-top" | ||
transitionTiming="ease-out" | ||
style={{ width: 200, height: 200 }} | ||
/> | ||
</Wrapper> | ||
<Wrapper label="Curl Up - Linear"> | ||
<ExpoImage | ||
source={{ uri: "https://picsum.photos/1600" }} | ||
transitionDuration={3000} | ||
transitionEffect="curl-up" | ||
transitionTiming="linear" | ||
style={{ width: 200, height: 200 }} | ||
/> | ||
</Wrapper> | ||
<Wrapper label="Cross Dissolve - Ease In Out"> | ||
<ExpoImage | ||
source={{ uri: "https://picsum.photos/1700" }} | ||
transitionDuration={3000} | ||
transitionEffect="cross-dissolve" | ||
transitionTiming="ease-in-out" | ||
style={{ width: 200, height: 200 }} | ||
/> | ||
</Wrapper> | ||
</View> | ||
</Section> | ||
</Container> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
wrapper: { | ||
flex: 1, | ||
display: "flex", | ||
flexDirection: "column", | ||
flexWrap: "wrap", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}, | ||
boxLabel: { | ||
margin: 10, | ||
flex: 1, | ||
}, | ||
}); | ||
|
||
export default withTheme(ExpoImageExample); |
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,86 @@ | ||
import React from "react"; | ||
import { | ||
Image, | ||
ImageContentPosition, | ||
ImageProps as ExpoImageProps, | ||
ImageContentFit, | ||
} from "expo-image"; | ||
import Config from "./Config"; | ||
|
||
interface ExtendedImageProps extends ExpoImageProps { | ||
transitionDuration?: number; | ||
transitionEffect?: | ||
| "cross-dissolve" | ||
| "flip-from-top" | ||
| "flip-from-right" | ||
| "flip-from-bottom" | ||
| "flip-from-left" | ||
| "curl-up" | ||
| "curl-down"; | ||
transitionTiming?: "ease-in-out" | "ease-in" | "ease-out" | "linear"; | ||
contentFit?: "cover" | "contain" | "fill" | "none" | "scale-down"; | ||
contentPosition?: ImageContentPosition; | ||
cachePolicy?: "none" | "disk" | "memory" | "memory-disk"; | ||
allowDownscaling?: boolean; | ||
blurRadius?: number; | ||
blurhash?: string; | ||
} | ||
|
||
const resizeModeToContentFit = ( | ||
resizeMode: "cover" | "contain" | "stretch" | "repeat" | "center" | ||
): ImageContentFit => { | ||
const mapping: Record<typeof resizeMode, ImageContentFit> = { | ||
cover: "cover", | ||
contain: "contain", | ||
stretch: "fill", | ||
repeat: "none", | ||
center: "scale-down", | ||
} as const; | ||
return mapping[resizeMode] ?? "cover"; | ||
}; | ||
|
||
const ExpoImage: React.FC<ExtendedImageProps> = ({ | ||
source, | ||
resizeMode = "cover", | ||
style, | ||
transitionDuration = 300, | ||
transitionEffect = "cross-dissolve", | ||
transitionTiming = "ease-in-out", | ||
contentFit = "cover", | ||
contentPosition = "center", | ||
cachePolicy = "memory-disk", | ||
allowDownscaling = true, | ||
blurRadius, | ||
blurhash, | ||
...props | ||
}) => { | ||
const imageSource = source ?? Config.placeholderImageURL; | ||
const finalContentFit = resizeMode | ||
? resizeModeToContentFit(resizeMode) | ||
: contentFit; | ||
|
||
const transition = { | ||
timing: transitionTiming, | ||
duration: transitionDuration, | ||
effect: transitionEffect, | ||
}; | ||
|
||
return ( | ||
<Image | ||
{...props} | ||
source={imageSource} | ||
contentFit={finalContentFit} | ||
placeholder={{ | ||
blurhash, | ||
}} | ||
transition={transition} | ||
contentPosition={contentPosition} | ||
cachePolicy={cachePolicy} | ||
allowDownscaling={allowDownscaling} | ||
blurRadius={blurRadius} | ||
style={style} | ||
/> | ||
); | ||
}; | ||
|
||
export default ExpoImage; |
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 |
---|---|---|
|
@@ -78,6 +78,7 @@ export { | |
LoadingIndicator, | ||
LottieAnimation, | ||
Timer, | ||
ExpoImage, | ||
} from "@draftbit/core"; | ||
|
||
export { | ||
|
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