사용 이유
React Native에서 Lottie를 구현하기 위해
@lottiefiles/dotlottie-react-native 라이브러리를 사용하다 발생한 에러에 대해 정리한다.
GitHub - LottieFiles/dotlottie-react-native: Official LottieFiles player for rendering Lottie and dotLottie animations in React
Official LottieFiles player for rendering Lottie and dotLottie animations in React Native - LottieFiles/dotlottie-react-native
github.com
문제
라이브러리를 사용하기 위해 설치 하고 빌드를 해보았다
다음과 같은 에러가 발생하며 빌드가 되지 않았다
❌ (node_modules/@lottiefiles/dotlottie-react-native/ios/DotlottieReactNativeViewManager.swift:131:22)
129 | // Unsubscribe state machine observer if it exists
130 | if let stateMachineObserver = self.stateMachineObserver, let animation = self.animation {
> 131 | _ = animation.stateMachineUnSubscribe(observer: stateMachineObserver)
| ^ value of type 'DotLottieAnimation' has no member 'stateMachineUnSubscribe'
132 | }
133 |
134 | self.observer = nil
이유
DotlottieReactNativeViewManager.swift 에 사용하는
stateMachineUnSubscribe(observer: stateMachineObserver) 가 잘못되어 생긴 오류
// 이 메소드가 변경 되어
_ = animation.stateMachineUnSubscribe(observer: stateMachineObserver)
// 이렇게 변경해야함
_ = animation.stateMachineUnsubscribe(stateMachineObserver)
해결방법
현재 설치되어있는 dotlottie-react-native에서 해당 코드를 직접 수정
node_modules/@lottiefiles/dotlottie-react-native/ios/DotlottieReactNativeViewManager.swift
_ = animation.stateMachineUnSubscribe(observer: stateMachineObserver) // 코드를
_ = animation.stateMachineUnsubscribe(stateMachineObserver) // 로 변경 후 빌드
참고
https://github.com/LottieFiles/dotlottie-react-native/issues/34