-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
LottieAnimationViewComponentView.mm
144 lines (109 loc) · 4.06 KB
/
LottieAnimationViewComponentView.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#import "LottieAnimationViewComponentView.h"
#import <react/renderer/components/lottiereactnative/ComponentDescriptors.h>
#import <react/renderer/components/lottiereactnative/EventEmitters.h>
#import <react/renderer/components/lottiereactnative/Props.h>
#import <react/renderer/components/lottiereactnative/RCTComponentViewHelpers.h>
#import "RCTFabricComponentsPlugins.h"
#import <React/RCTView.h>
#import "LottieContainerView.h"
#import "RNLottieFabricConversions.h"
using namespace facebook::react;
@interface LottieAnimationViewComponentView () <RCTLottieAnimationViewViewProtocol>
@end
@implementation LottieAnimationViewComponentView {
LottieContainerView *_view;
}
- (instancetype) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const LottieAnimationViewProps>();
_props = defaultProps;
_view = [LottieContainerView new];
_view.delegate = self;
self.contentView = _view;
}
return self;
}
#pragma mark - RCTComponentViewProtocol
+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<LottieAnimationViewComponentDescriptor>();
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
const auto &oldLottieProps = *std::static_pointer_cast<const LottieAnimationViewProps>(_props);
const auto &newLottieProps = *std::static_pointer_cast<const LottieAnimationViewProps>(props);
if(oldLottieProps.resizeMode != newLottieProps.resizeMode) {
[_view setResizeMode:RCTNSStringFromString(newLottieProps.resizeMode)];
}
if(oldLottieProps.sourceJson != newLottieProps.sourceJson) {
[_view setSourceJson:RCTNSStringFromString(newLottieProps.sourceJson)];
}
if(oldLottieProps.sourceName != newLottieProps.sourceName) {
[_view setSourceName:RCTNSStringFromString(newLottieProps.sourceName)];
}
if(oldLottieProps.sourceURL != newLottieProps.sourceURL) {
[_view setSourceURL:RCTNSStringFromString(newLottieProps.sourceURL)];
}
if(oldLottieProps.progress != newLottieProps.progress) {
[_view setProgress:newLottieProps.progress];
}
if(oldLottieProps.loop != newLottieProps.loop) {
[_view setLoop:newLottieProps.loop];
}
if(oldLottieProps.speed != newLottieProps.speed) {
[_view setSpeed:newLottieProps.speed];
}
if(oldLottieProps.colorFilters != newLottieProps.colorFilters) {
[_view setColorFilters:convertColorFilters(newLottieProps.colorFilters)];
}
if(oldLottieProps.textFiltersIOS != newLottieProps.textFiltersIOS) {
[_view setTextFiltersIOS:convertTextFilters(newLottieProps.textFiltersIOS)];
}
if(oldLottieProps.renderMode != newLottieProps.renderMode) {
[_view setRenderMode:RCTNSStringFromString(newLottieProps.renderMode)];
}
if(oldLottieProps.autoPlay != newLottieProps.autoPlay) {
[_view setAutoPlay:newLottieProps.autoPlay];
}
[super updateProps:props oldProps:oldProps];
}
#pragma mark - Native Commands
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
{
RCTLottieAnimationViewHandleCommand(self, commandName, args);
}
- (void) play:(NSInteger)startFrame endFrame:(NSInteger)endFrame
{
if (startFrame != -1 && endFrame != -1) {
[_view playFromFrame:@(startFrame) toFrame:endFrame];
} else {
[_view play];
}
}
- (void) reset
{
[_view reset];
}
- (void) pause
{
[_view pause];
}
- (void) resume
{
[_view resume];
}
- (void)onAnimationFinishWithIsCancelled:(bool)isCancelled
{
if(!_eventEmitter) {
return;
}
LottieAnimationViewEventEmitter::OnAnimationFinish event = {
.isCancelled = isCancelled
};
std::dynamic_pointer_cast<const LottieAnimationViewEventEmitter>(_eventEmitter)->onAnimationFinish(event);
}
@end
Class<RCTComponentViewProtocol> LottieAnimationViewCls(void)
{
return LottieAnimationViewComponentView.class;
}