Skip to content

Commit

Permalink
fix: prevent jumping to end frame (#1061)
Browse files Browse the repository at this point in the history
No need to force the animation to be on end frame anymore.

Fixes: #1049
  • Loading branch information
matinzd committed Jul 24, 2023
1 parent 9fd591f commit 0c04180
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
56 changes: 56 additions & 0 deletions apps/paper/src/FramesExample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import LottieView from 'lottie-react-native';
import {useRef, useState} from 'react';
import {Button, StyleSheet, TextInput, View} from 'react-native';

export const FramesExample = () => {
const [startFrame, setStartFrame] = useState(0);
const [endFrame, setEndFrame] = useState(15);

const ref = useRef<LottieView>(null);

const playFrames = () => {
ref.current?.play(startFrame, endFrame);
};

return (
<View style={styles.container}>
<LottieView
ref={ref}
source={require('./animations/LottieWalkthrough.json')}
autoPlay={false}
loop={false}
style={styles.lottie}
/>
<TextInput
key={'startFrame'}
defaultValue={'0'}
style={styles.input}
placeholder="start frame"
onChangeText={e => setStartFrame(parseInt(e ?? 0))}
/>
<TextInput
key={'endFrame'}
defaultValue={'15'}
style={styles.input}
placeholder="end frame"
onChangeText={e => setEndFrame(parseInt(e ?? 0))}
/>
<Button title={'Play frames'} onPress={playFrames} />
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
gap: 16,
},
lottie: {
width: 200,
height: 200,
resizeMode: 'contain',
},
input: {borderWidth: 1, borderColor: 'black', width: 200, padding: 4},
});
4 changes: 0 additions & 4 deletions packages/core/ios/LottieReactNative/ContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class ContainerView: RCTView {
onFinish(["isCancelled": !animationFinished])
}
self.delegate?.onAnimationFinish(isCancelled: !animationFinished);
if (animationFinished) {
// Force the animation to stay on the last frame when the animation ends
self.animationView?.currentProgress = 1;
}
};
}

Expand Down

0 comments on commit 0c04180

Please sign in to comment.