-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# isMotionAnimation | ||
|
||
`isMotionAnimation` can be used to check if a style key is considered a motion animation, i.e.: `translateX`, `left`, `right`, etc... | ||
|
||
## Syntax | ||
|
||
```js | ||
function isMotionAnimation(property: ViewStyle): boolean {} | ||
``` | ||
|
||
| Property | Description | | ||
| -------- | --------------------- | | ||
| property | The property to check | | ||
|
||
## Example | ||
|
||
```tsx | ||
import * as React from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { | ||
isMotionAnimation, | ||
useAMAContext, | ||
useAccessibleAnimationDuration, | ||
} from 'react-native-ama'; | ||
import Animated, { | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withSpring, | ||
withTiming, | ||
} from 'react-native-reanimated'; | ||
|
||
export const ReanimatedReduceMotionScreen = () => { | ||
const { getAnimationDuration } = useAccessibleAnimationDuration(); | ||
const { isReduceMotionEnabled } = useAMAContext(); | ||
const value = useSharedValue(0); | ||
|
||
const animatedStyles = useAnimatedStyle(() => { | ||
return { | ||
transform: [{ translateX: value.value * 255 }], | ||
}; | ||
}); | ||
|
||
const testWithSpring = () => { | ||
const to = Math.random(); | ||
|
||
value.value = | ||
isReduceMotionEnabled && isMotionAnimation('translateX') | ||
? withTiming(to, { duration: 0 }) | ||
: withSpring(to); | ||
}; | ||
|
||
return ( | ||
<View style={styles.view}> | ||
<Animated.View style={[styles.box, animatedStyles]} /> | ||
|
||
<CTAPressable title="Test: withSpring" onPress={testWithSpring} /> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
view: { | ||
paddingHorizontal: 24, | ||
}, | ||
box: { | ||
width: 100, | ||
height: 100, | ||
borderRadius: 20, | ||
backgroundColor: 'red', | ||
}, | ||
}); | ||
``` |