-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(template): add Animations and Gestures to template
Remove workaround to download template required in 0.75.0. release-npm
- Loading branch information
Showing
10 changed files
with
155 additions
and
22 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
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,84 @@ | ||
import React, { LegacyRef, MutableRefObject, useEffect, useRef } from 'react' | ||
import { Text, View, Animated } from 'react-native' | ||
import { createStyles } from 'responsive-react-native' | ||
import { Color, Space } from '../style' | ||
|
||
const styles = createStyles({ | ||
wrapper: { | ||
flexDirection: 'row', | ||
gap: Space.medium, | ||
}, | ||
box: { | ||
justifyContent: 'center', | ||
padding: Space.medium, | ||
borderRadius: Space.medium, | ||
backgroundColor: Color.highlight, | ||
}, | ||
text: { | ||
fontFamily: { ios: 'Courier', android: 'monospace' }, | ||
}, | ||
}) | ||
|
||
function animateNativeProps(view?: MutableRefObject<View | undefined>) { | ||
if (!view?.current) { | ||
return null | ||
} | ||
|
||
let opacity = 0 | ||
let increasing = true | ||
|
||
return setInterval(() => { | ||
if (increasing) { | ||
opacity += 0.01 | ||
if (opacity >= 1) { | ||
increasing = false | ||
} | ||
} else { | ||
opacity -= 0.01 | ||
if (opacity <= 0) { | ||
increasing = true | ||
} | ||
} | ||
|
||
view.current?.setNativeProps({ | ||
style: { opacity }, | ||
}) | ||
}, 10) | ||
} | ||
|
||
export function Animation() { | ||
const firstBox = useRef<View>() | ||
const opacityValue = useRef(new Animated.Value(0)).current | ||
|
||
useEffect(() => { | ||
const intervalId = animateNativeProps(firstBox) | ||
|
||
Animated.loop( | ||
Animated.sequence([ | ||
Animated.timing(opacityValue, { | ||
toValue: 1, | ||
duration: 1500, | ||
useNativeDriver: true, | ||
}), | ||
Animated.timing(opacityValue, { | ||
toValue: 0, | ||
duration: 1500, | ||
useNativeDriver: true, | ||
}), | ||
]) | ||
).start() | ||
|
||
return () => (intervalId ? clearInterval(intervalId) : undefined) | ||
}, [opacityValue]) | ||
|
||
return ( | ||
<View style={styles.wrapper}> | ||
<View ref={firstBox as LegacyRef<View>} style={styles.box}> | ||
<Text style={styles.text}>setNativeProps</Text> | ||
</View> | ||
<Animated.View style={[styles.box, { opacity: opacityValue }]}> | ||
<Text style={styles.text}>Animated.Value</Text> | ||
</Animated.View> | ||
</View> | ||
) | ||
} |
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,48 @@ | ||
import React, { LegacyRef, useRef } from 'react' | ||
import { PanResponder, Text, View } from 'react-native' | ||
import { createStyles } from 'responsive-react-native' | ||
import { Color, Font, Space } from '../style' | ||
|
||
const styles = createStyles({ | ||
wrapper: { | ||
flexDirection: 'row', | ||
gap: Space.medium, | ||
}, | ||
box: { | ||
justifyContent: 'center', | ||
padding: Space.medium, | ||
borderRadius: Space.medium, | ||
backgroundColor: Color.highlight, | ||
}, | ||
}) | ||
|
||
export function Gesture() { | ||
const box = useRef<View>() | ||
const panResponder = React.useRef( | ||
PanResponder.create({ | ||
onStartShouldSetPanResponder: () => true, | ||
onPanResponderMove: (_event, gestureState) => { | ||
box.current?.setNativeProps({ | ||
style: { | ||
transform: [{ translateX: gestureState.dx }, { translateY: gestureState.dy }], | ||
}, | ||
}) | ||
}, | ||
onPanResponderRelease: () => { | ||
box.current?.setNativeProps({ | ||
style: { | ||
transform: [{ translateX: 0 }, { translateY: 0 }], | ||
}, | ||
}) | ||
}, | ||
}) | ||
).current | ||
|
||
return ( | ||
<View style={styles.wrapper}> | ||
<View ref={box as LegacyRef<View>} {...panResponder.panHandlers} style={styles.box}> | ||
<Text style={Font.bold}>Drag around!</Text> | ||
</View> | ||
</View> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
{ | ||
"extends": "@react-native/typescript-config/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "Bundler" | ||
} | ||
"extends": "@react-native/typescript-config/tsconfig.json", | ||
"compilerOptions": { | ||
"module": "ESNext" | ||
} | ||
} | ||
|
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