Skip to content

Commit 5651fee

Browse files
committed
feat: add examples to FabricExample
1 parent 26eabb5 commit 5651fee

34 files changed

+1123
-118
lines changed

FabricExample/App.js

Lines changed: 0 additions & 117 deletions
This file was deleted.

FabricExample/android/gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
3838
# to write custom TurboModules/Fabric components OR use libraries that
3939
# are providing them.
4040
newArchEnabled=false
41+
42+
disableMultipleInstancesCheck=true

FabricExample/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import {AppRegistry} from 'react-native';
6-
import App from './App';
6+
import App from './src'
77
import {name as appName} from './app.json';
88

99
AppRegistry.registerComponent(appName, () => App);

FabricExample/ios/FabricExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
13B07FAE1A68108700A75B9A /* FabricExample */ = {
8787
isa = PBXGroup;
8888
children = (
89+
236DEBB129377AED000A670D /* Fonts */,
8990
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
9091
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
9192
13B07FB51A68108700A75B9A /* Images.xcassets */,
@@ -96,6 +97,13 @@
9697
name = FabricExample;
9798
sourceTree = "<group>";
9899
};
100+
236DEBB129377AED000A670D /* Fonts */ = {
101+
isa = PBXGroup;
102+
children = (
103+
);
104+
path = Fonts;
105+
sourceTree = "<group>";
106+
};
99107
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
100108
isa = PBXGroup;
101109
children = (
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React, { useCallback, useMemo, useState } from 'react'
2+
import { StyleSheet, View } from 'react-native'
3+
import SectionFlex from './SectionFlex'
4+
import FastImage, { FastImageProps } from 'react-native-fast-image'
5+
import Section from './Section'
6+
import FeatureText from './FeatureText'
7+
import { useCacheBust } from './useCacheBust'
8+
9+
const GIF_URL =
10+
'https://cdn-images-1.medium.com/max/1600/1*-CY5bU4OqiJRox7G00sftw.gif'
11+
12+
interface AutoSizingImageProps extends FastImageProps {
13+
onLoad?: (event: any) => void
14+
defaultHeight?: number
15+
width: number
16+
style?: any
17+
}
18+
19+
const AutoSizingImage = (props: AutoSizingImageProps) => {
20+
const [dimensions, setDimensions] = useState({
21+
height: 0,
22+
width: 0,
23+
})
24+
25+
const propsOnLoad = props.onLoad
26+
const onLoad = useCallback(
27+
(e: any) => {
28+
const {
29+
nativeEvent: { width, height },
30+
} = e
31+
setDimensions({ width, height })
32+
if (propsOnLoad) {
33+
propsOnLoad(e)
34+
}
35+
},
36+
[propsOnLoad],
37+
)
38+
39+
const height = useMemo(() => {
40+
if (!dimensions.height) {
41+
return props.defaultHeight === undefined ? 300 : props.defaultHeight
42+
}
43+
const ratio = dimensions.height / dimensions.width
44+
return props.width * ratio
45+
}, [dimensions.height, dimensions.width, props.defaultHeight, props.width])
46+
return (
47+
<FastImage
48+
{...props}
49+
onLoad={onLoad}
50+
style={[{ width: props.width, height }, props.style]}
51+
/>
52+
)
53+
}
54+
55+
export const AutoSizeExample = () => {
56+
const { bust, url } = useCacheBust(GIF_URL)
57+
return (
58+
<View>
59+
<Section>
60+
<FeatureText text="• AutoSize." />
61+
</Section>
62+
<SectionFlex onPress={bust}>
63+
<AutoSizingImage
64+
style={styles.image}
65+
width={200}
66+
source={{ uri: url }}
67+
/>
68+
</SectionFlex>
69+
</View>
70+
)
71+
}
72+
73+
const styles = StyleSheet.create({
74+
image: {
75+
backgroundColor: '#ddd',
76+
margin: 20,
77+
flex: 0,
78+
},
79+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react'
2+
import { StyleSheet, View } from 'react-native'
3+
import SectionFlex from './SectionFlex'
4+
import FastImage from 'react-native-fast-image'
5+
import Section from './Section'
6+
import FeatureText from './FeatureText'
7+
import { useCacheBust } from './useCacheBust'
8+
9+
const IMAGE_URL = 'https://media.giphy.com/media/GEsoqZDGVoisw/giphy.gif'
10+
11+
export const BorderRadiusExample = () => {
12+
const { query, bust } = useCacheBust('')
13+
return (
14+
<View>
15+
<Section>
16+
<FeatureText text="• Border radius." />
17+
</Section>
18+
<SectionFlex onPress={bust}>
19+
<FastImage
20+
style={styles.imageSquare}
21+
source={{
22+
uri: IMAGE_URL + query,
23+
}}
24+
/>
25+
<FastImage
26+
style={styles.imageRectangular}
27+
source={{
28+
uri: IMAGE_URL + query,
29+
}}
30+
/>
31+
</SectionFlex>
32+
</View>
33+
)
34+
}
35+
36+
const styles = StyleSheet.create({
37+
imageSquare: {
38+
borderRadius: 50,
39+
height: 100,
40+
backgroundColor: '#ddd',
41+
margin: 20,
42+
width: 100,
43+
flex: 0,
44+
},
45+
imageRectangular: {
46+
borderRadius: 50,
47+
borderTopLeftRadius: 10,
48+
borderBottomRightRadius: 10,
49+
height: 100,
50+
backgroundColor: '#ddd',
51+
margin: 20,
52+
flex: 1,
53+
},
54+
plus: {
55+
width: 30,
56+
height: 30,
57+
position: 'absolute',
58+
bottom: 0,
59+
right: 0,
60+
},
61+
})

FabricExample/src/BulletText.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import FeatureText from './FeatureText'
3+
4+
interface BulletTextProps {
5+
text?: string
6+
children?: any
7+
}
8+
9+
const BulletText = ({ text, children }: BulletTextProps) => (
10+
<FeatureText text={`• ${text || children} •`} />
11+
)
12+
13+
export default BulletText

FabricExample/src/Button.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react'
2+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
3+
4+
interface ButtonProps {
5+
text: string
6+
onPress: () => void
7+
}
8+
9+
const Button = ({ text, onPress }: ButtonProps) => (
10+
<TouchableOpacity onPress={onPress}>
11+
<View style={styles.button}>
12+
<Text style={styles.text}>{text}</Text>
13+
</View>
14+
</TouchableOpacity>
15+
)
16+
17+
const styles = StyleSheet.create({
18+
button: {
19+
backgroundColor: 'black',
20+
margin: 10,
21+
height: 44,
22+
paddingLeft: 10,
23+
paddingRight: 10,
24+
borderRadius: 10,
25+
alignItems: 'center',
26+
justifyContent: 'center',
27+
},
28+
text: {
29+
color: 'white',
30+
},
31+
})
32+
33+
export default Button
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
import { Image } from 'react-native'
3+
import { ImageGrid } from './ImageGrid'
4+
5+
const DefaultImageGrid = () => <ImageGrid ImageComponent={Image} />
6+
7+
export default DefaultImageGrid

0 commit comments

Comments
 (0)