react-native-reanimated#Node TypeScript Examples
The following examples show how to use
react-native-reanimated#Node.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bar.tsx From expo-progress with MIT License | 4 votes |
function ProgressBar({
isIndeterminate = false,
duration = isIndeterminate ? 1000 : 500,
isAnimated = false,
progress = isIndeterminate ? 0.5 : 0,
height = 7,
borderRadius = height * 0.5,
// Default iOS blue
color = '#007aff',
trackColor = 'transparent',
style,
trackImage,
progressImage,
}: ProgressBarProps) {
const [width, setWidth] = React.useState(0);
const progressValue = useValue(isAnimated ? 0 : progress);
const indeterminateValue = useValue(0);
const animatedWidth = interpolate(
clamp(progressValue, minProgress, maxProgress),
{
inputRange: [minProgress, maxProgress],
outputRange: [0, width],
extrapolate: Extrapolate.CLAMP,
}
);
useCode(() => {
if (isAnimated) {
return set(
progressValue,
timing({
from: progressValue,
to: progress,
duration,
})
);
} else {
return set(progressValue, progress);
}
}, [progress]);
useCode(() => {
if (isIndeterminate) {
const loopingIndeterminateValue = loop({
autoStart: true,
boomerang: false,
duration,
});
return set(indeterminateValue, loopingIndeterminateValue);
}
const animatedIndeterminateValue = timing({
from: indeterminateValue,
to: 0,
});
return set(indeterminateValue, animatedIndeterminateValue);
}, [isIndeterminate]);
// todo: web has a bug where the reanimated Animated.View style is not updating unless this is an animated value.
let translateX: Node<number> | number = useValue(0);
if (isIndeterminate) {
translateX = interpolate(indeterminateValue, {
inputRange: [0, 1],
outputRange: [multiply(-1, animatedWidth), width],
});
}
return (
<ImageBackground
onLayout={(e: LayoutChangeEvent) => {
setWidth(e.nativeEvent.layout.width);
}}
resizeMode={'stretch'}
style={[
styles.container,
{
height,
borderRadius,
backgroundColor: trackColor,
},
style,
]}
// @ts-ignore
source={trackImage}
>
<Animated.Image
style={[
styles.bar,
{
width: animatedWidth,
transform: [
{
translateX,
},
],
backgroundColor: color,
borderRadius,
},
]}
// @ts-ignore
source={progressImage}
/>
</ImageBackground>
);
}