|
| 1 | +import * as React from "react"; |
| 2 | +import { View, StyleSheet, Text } from "react-native"; |
| 3 | +import { ExpoImage, withTheme } from "@draftbit/ui"; |
| 4 | +import Section, { Container } from "./Section"; |
| 5 | + |
| 6 | +interface WrapperProps { |
| 7 | + label: string; |
| 8 | + children: React.ReactNode; |
| 9 | +} |
| 10 | + |
| 11 | +const Wrapper: React.FC<WrapperProps> = ({ label, children }) => { |
| 12 | + return ( |
| 13 | + <View style={styles.wrapper}> |
| 14 | + <View style={styles.boxLabel}> |
| 15 | + <Text>{label}</Text> |
| 16 | + </View> |
| 17 | + <View>{children}</View> |
| 18 | + </View> |
| 19 | + ); |
| 20 | +}; |
| 21 | + |
| 22 | +const ExpoImageExample: React.FC = () => { |
| 23 | + return ( |
| 24 | + <Container style={{}}> |
| 25 | + <Section title="Image Examples" style={{}}> |
| 26 | + <View style={{ flexDirection: "row" }}> |
| 27 | + <Wrapper label="Basic remote image"> |
| 28 | + <ExpoImage |
| 29 | + source={{ |
| 30 | + uri: "https://picsum.photos/1100", |
| 31 | + }} |
| 32 | + style={{ |
| 33 | + width: 200, |
| 34 | + height: 200, |
| 35 | + }} |
| 36 | + /> |
| 37 | + </Wrapper> |
| 38 | + <Wrapper label="Local image"> |
| 39 | + <ExpoImage |
| 40 | + source={require("./assets/images/hamburger.png")} |
| 41 | + style={{ |
| 42 | + width: 200, |
| 43 | + height: 200, |
| 44 | + }} |
| 45 | + /> |
| 46 | + </Wrapper> |
| 47 | + </View> |
| 48 | + <View style={{ flexDirection: "row" }}> |
| 49 | + <Wrapper label="Content fit: contain"> |
| 50 | + <ExpoImage |
| 51 | + source={{ |
| 52 | + uri: "https://picsum.photos/1300", |
| 53 | + }} |
| 54 | + contentFit="contain" |
| 55 | + style={{ |
| 56 | + width: 200, |
| 57 | + height: 200, |
| 58 | + backgroundColor: "#f0f0f0", |
| 59 | + }} |
| 60 | + /> |
| 61 | + </Wrapper> |
| 62 | + <Wrapper label="With blur hash"> |
| 63 | + <ExpoImage |
| 64 | + source={{ |
| 65 | + uri: "https://picsum.photos/seed/696/3000/2000", |
| 66 | + }} |
| 67 | + blurhash="LEHLk~WB2yk8pyo0adR*.7kCMdnj" |
| 68 | + style={{ |
| 69 | + width: 200, |
| 70 | + height: 200, |
| 71 | + }} |
| 72 | + /> |
| 73 | + </Wrapper> |
| 74 | + </View> |
| 75 | + </Section> |
| 76 | + <Section title="SVG Image" style={styles.wrapper}> |
| 77 | + <Wrapper label="Remote SVG Image"> |
| 78 | + <ExpoImage |
| 79 | + source={{ |
| 80 | + uri: "https://upload.wikimedia.org/wikipedia/commons/3/30/Vector-based_example.svg", |
| 81 | + }} |
| 82 | + style={{ |
| 83 | + width: 200, |
| 84 | + height: 200, |
| 85 | + }} |
| 86 | + /> |
| 87 | + </Wrapper> |
| 88 | + <Wrapper label="Local SVG Image"> |
| 89 | + <ExpoImage |
| 90 | + source={require("./assets/images/example.svg")} |
| 91 | + style={{ |
| 92 | + width: 200, |
| 93 | + height: 200, |
| 94 | + }} |
| 95 | + /> |
| 96 | + </Wrapper> |
| 97 | + </Section> |
| 98 | + <Section title="Transition Effects" style={{}}> |
| 99 | + <View style={{ flexDirection: "row", flexWrap: "wrap" }}> |
| 100 | + <Wrapper label="Cross Dissolve - Ease In Out"> |
| 101 | + <ExpoImage |
| 102 | + source={{ uri: "https://picsum.photos/1400" }} |
| 103 | + transitionDuration={3000} |
| 104 | + transitionEffect="cross-dissolve" |
| 105 | + transitionTiming="ease-in-out" |
| 106 | + style={{ width: 150, height: 150 }} |
| 107 | + /> |
| 108 | + </Wrapper> |
| 109 | + <Wrapper label="Flip from Top - Ease Out"> |
| 110 | + <ExpoImage |
| 111 | + source={{ uri: "https://picsum.photos/1500" }} |
| 112 | + transitionDuration={3000} |
| 113 | + transitionEffect="flip-from-top" |
| 114 | + transitionTiming="ease-out" |
| 115 | + style={{ width: 150, height: 150 }} |
| 116 | + /> |
| 117 | + </Wrapper> |
| 118 | + </View> |
| 119 | + </Section> |
| 120 | + <Section title="Transition Timing" style={{}}> |
| 121 | + <View style={{ flexDirection: "row", flexWrap: "wrap" }}> |
| 122 | + <Wrapper label="Curl Up - Linear"> |
| 123 | + <ExpoImage |
| 124 | + source={{ uri: "https://picsum.photos/1600" }} |
| 125 | + transitionDuration={3000} |
| 126 | + transitionEffect="curl-up" |
| 127 | + transitionTiming="linear" |
| 128 | + style={{ width: 150, height: 150 }} |
| 129 | + /> |
| 130 | + </Wrapper> |
| 131 | + <Wrapper label="Cross Dissolve - Ease In Out"> |
| 132 | + <ExpoImage |
| 133 | + source={{ uri: "https://picsum.photos/1700" }} |
| 134 | + transitionDuration={3000} |
| 135 | + transitionEffect="cross-dissolve" |
| 136 | + transitionTiming="ease-in-out" |
| 137 | + style={{ width: 150, height: 150 }} |
| 138 | + /> |
| 139 | + </Wrapper> |
| 140 | + </View> |
| 141 | + </Section> |
| 142 | + </Container> |
| 143 | + ); |
| 144 | +}; |
| 145 | + |
| 146 | +const styles = StyleSheet.create({ |
| 147 | + wrapper: { |
| 148 | + flex: 1, |
| 149 | + display: "flex", |
| 150 | + flexDirection: "column", |
| 151 | + flexWrap: "wrap", |
| 152 | + justifyContent: "center", |
| 153 | + alignItems: "center", |
| 154 | + }, |
| 155 | + boxLabel: { |
| 156 | + margin: 10, |
| 157 | + flex: 1, |
| 158 | + }, |
| 159 | +}); |
| 160 | + |
| 161 | +export default withTheme(ExpoImageExample); |
0 commit comments