Skip to content

Commit f8bc281

Browse files
committed
fix: resolve race condition crash when rendering multiple DotLottie components
1 parent eb7f403 commit f8bc281

File tree

3 files changed

+97
-13
lines changed

3 files changed

+97
-13
lines changed

example/App.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from 'react-native';
1010
import { LifecycleExample } from './examples/LifecycleExample';
1111
import { StateMachineExample } from './examples/StateMachineExample';
12+
import { MultipleAnimationsTest } from './examples/MultipleAnimationsTest';
1213

1314
type ExampleDescriptor = {
1415
key: string;
@@ -18,6 +19,13 @@ type ExampleDescriptor = {
1819
};
1920

2021
const EXAMPLES: ExampleDescriptor[] = [
22+
{
23+
key: 'multiple-animations',
24+
title: 'Multiple Animations Test',
25+
description:
26+
'Rendering multiple DotLottie components simultaneously.',
27+
Component: MultipleAnimationsTest,
28+
},
2129
{
2230
key: 'state-machine',
2331
title: 'State Machine Playground',
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
3+
import { DotLottie } from '@lottiefiles/dotlottie-react-native';
4+
import { ScrollView, StyleSheet, Text, View } from 'react-native';
5+
6+
const TEST_ANIMATIONS = [
7+
{
8+
id: 'animation-1',
9+
source: 'https://lottie.host/50f65a48-2f50-432f-b47a-4e6b271625c0/O4jvHbwypB.lottie',
10+
label: 'Animation 1',
11+
},
12+
{
13+
id: 'animation-2',
14+
source: 'https://lottie.host/6037ce8d-16b8-4922-a013-bbb42336605d/rhoaleeUiW.lottie',
15+
label: 'Animation 2',
16+
},
17+
{
18+
id: 'animation-3',
19+
source: 'https://lottie.host/ecfc8e66-1a24-4723-90a5-d158bee66db4/kJfdmk9Rj6.lottie',
20+
label: 'Animation 3',
21+
},
22+
];
23+
24+
export function MultipleAnimationsTest() {
25+
return (
26+
<ScrollView contentContainerStyle={styles.container}>
27+
<View style={styles.animationGrid}>
28+
{TEST_ANIMATIONS.map((anim) => (
29+
<View key={anim.id} style={styles.animationCard}>
30+
<Text style={styles.label}>{anim.label}</Text>
31+
<DotLottie
32+
source={{
33+
uri: anim.source
34+
}}
35+
style={styles.animation}
36+
autoplay
37+
loop
38+
/>
39+
</View>
40+
))}
41+
</View>
42+
</ScrollView>
43+
);
44+
}
45+
46+
const styles = StyleSheet.create({
47+
container: {
48+
flexGrow: 1,
49+
padding: 20,
50+
backgroundColor: '#fff',
51+
},
52+
title: {
53+
fontSize: 24,
54+
fontWeight: 'bold',
55+
marginBottom: 8,
56+
},
57+
subtitle: {
58+
fontSize: 14,
59+
color: '#666',
60+
marginBottom: 24,
61+
},
62+
animationGrid: {
63+
gap: 16,
64+
},
65+
animationCard: {
66+
backgroundColor: '#f5f5f5',
67+
borderRadius: 8,
68+
padding: 16,
69+
alignItems: 'center',
70+
},
71+
label: {
72+
fontSize: 16,
73+
fontWeight: '600',
74+
marginBottom: 12,
75+
},
76+
animation: {
77+
width: 200,
78+
height: 200,
79+
},
80+
status: {
81+
marginTop: 24,
82+
fontSize: 16,
83+
fontWeight: 'bold',
84+
color: '#4CAF50',
85+
textAlign: 'center',
86+
},
87+
});

ios/DotlottieReactNativeViewManager.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -610,19 +610,8 @@ class DotlottieReactNativeView: UIView {
610610
}
611611

612612
pendingAnimationUpdate = true
613-
DispatchQueue.main.async { [weak self] in
614-
guard let self = self else {
615-
return
616-
}
617-
618-
if self.isReleased {
619-
self.pendingAnimationUpdate = false
620-
return
621-
}
622-
623-
self.pendingAnimationUpdate = false
624-
self.dataStore.createAnimation()
625-
}
613+
dataStore.createAnimation()
614+
pendingAnimationUpdate = false
626615
}
627616

628617
@objc var source: NSString = "" {

0 commit comments

Comments
 (0)