Skip to content

Commit c5f1a07

Browse files
authored
fix: @granite-js/lottie LottieView props (#239)
* fix: lottie duration not working * fix: remove contianer style * chore: changeset * refact: memo * chore: annotation * chore: format
1 parent 9793f61 commit c5f1a07

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

.changeset/tiny-paws-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-granite-app': patch
3+
---
4+
5+
fix: @granite-js/lottie LottieView duration doesn't work

packages/lottie/src/GraniteLottieView.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const LottieView = forwardRef<LottieViewRef, LottieViewProps>((props, ref
6464
style,
6565
progress,
6666
speed = 1,
67+
duration,
6768
loop = true,
6869
autoPlay = false,
6970
resizeMode = 'contain',
@@ -112,6 +113,14 @@ export const LottieView = forwardRef<LottieViewRef, LottieViewProps>((props, ref
112113

113114
// Resolve source
114115
const resolvedSource = useMemo(() => resolveSource(source), [source]);
116+
const resolvedSpeed = useMemo(() => {
117+
const { sourceJson } = resolvedSource;
118+
if (duration && sourceJson && (source as AnimationObject).fr) {
119+
// reference: https://github.com/lottie-react-native/lottie-react-native/blob/a7a99137b6cd947a4b2881e3a8c2214b114015bc/packages/core/src/LottieView/index.tsx#L119-L124
120+
return Math.round((((source as AnimationObject).op / (source as AnimationObject).fr) * 1000) / duration);
121+
}
122+
return speed;
123+
}, [duration, resolvedSource, source, speed]);
115124

116125
// Event handlers
117126
const handleAnimationFinish = useCallback(
@@ -143,7 +152,7 @@ export const LottieView = forwardRef<LottieViewRef, LottieViewProps>((props, ref
143152
testID,
144153
...resolvedSource,
145154
progress,
146-
speed,
155+
speed: resolvedSpeed,
147156
loop,
148157
autoPlay,
149158
resizeMode,
@@ -168,6 +177,7 @@ export const LottieView = forwardRef<LottieViewRef, LottieViewProps>((props, ref
168177
}
169178

170179
return <NativeGraniteLottieView ref={nativeRef} {...nativeProps} />;
180+
171181
});
172182

173183
LottieView.displayName = 'LottieView';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// This file is auto-generated by the generate-fingerprint script.
2-
module.exports = '505c9a26f7cf43e683e3658753c3552d';
2+
module.exports = '4d29d584985a345e73633aaa182eec37';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// This file is auto-generated by the generate-fingerprint script.
2-
export default '505c9a26f7cf43e683e3658753c3552d';
2+
export default '4d29d584985a345e73633aaa182eec37';

0 commit comments

Comments
 (0)