|
1 | 1 | #import "LoaderKitView.h" |
| 2 | +#import "NVActivityIndicatorView.h" |
| 3 | +#import "React/RCTConvert.h" |
| 4 | + |
| 5 | +static const NSDictionary *nameToTypeMap = @{ |
| 6 | + @"BallPulse": @(NVActivityIndicatorTypeBallPulse), |
| 7 | + @"BallGridPulse": @(NVActivityIndicatorTypeBallGridPulse), |
| 8 | + @"BallClipRotate": @(NVActivityIndicatorTypeBallClipRotate), |
| 9 | + @"SquareSpin": @(NVActivityIndicatorTypeSquareSpin), |
| 10 | + @"BallClipRotatePulse": @(NVActivityIndicatorTypeBallClipRotatePulse), |
| 11 | + @"BallClipRotateMultiple": @(NVActivityIndicatorTypeBallClipRotateMultiple), |
| 12 | + @"BallPulseRise": @(NVActivityIndicatorTypeBallPulseRise), |
| 13 | + @"BallRotate": @(NVActivityIndicatorTypeBallRotate), |
| 14 | + @"CubeTransition": @(NVActivityIndicatorTypeCubeTransition), |
| 15 | + @"BallZigZag": @(NVActivityIndicatorTypeBallZigZag), |
| 16 | + @"BallZigZagDeflect": @(NVActivityIndicatorTypeBallZigZagDeflect), |
| 17 | + @"BallTrianglePath": @(NVActivityIndicatorTypeBallTrianglePath), |
| 18 | + @"BallScale": @(NVActivityIndicatorTypeBallScale), |
| 19 | + @"LineScale": @(NVActivityIndicatorTypeLineScale), |
| 20 | + @"LineScaleParty": @(NVActivityIndicatorTypeLineScaleParty), |
| 21 | + @"BallScaleMultiple": @(NVActivityIndicatorTypeBallScaleMultiple), |
| 22 | + @"BallPulseSync": @(NVActivityIndicatorTypeBallPulseSync), |
| 23 | + @"BallBeat": @(NVActivityIndicatorTypeBallBeat), |
| 24 | + @"LineScalePulseOut": @(NVActivityIndicatorTypeLineScalePulseOut), |
| 25 | + @"LineScalePulseOutRapid": @(NVActivityIndicatorTypeLineScalePulseOutRapid), |
| 26 | + @"BallScaleRipple": @(NVActivityIndicatorTypeBallScaleRipple), |
| 27 | + @"BallScaleRippleMultiple": @(NVActivityIndicatorTypeBallScaleRippleMultiple), |
| 28 | + @"BallSpinFadeLoader": @(NVActivityIndicatorTypeBallSpinFadeLoader), |
| 29 | + @"LineSpinFadeLoader": @(NVActivityIndicatorTypeLineSpinFadeLoader), |
| 30 | + @"TriangleSkewSpin": @(NVActivityIndicatorTypeTriangleSkewSpin), |
| 31 | + @"Pacman": @(NVActivityIndicatorTypePacman), |
| 32 | + @"BallGridBeat": @(NVActivityIndicatorTypeBallGridBeat), |
| 33 | + @"SemiCircleSpin": @(NVActivityIndicatorTypeSemiCircleSpin), |
| 34 | + @"BallRotateChase": @(NVActivityIndicatorTypeBallRotateChase), |
| 35 | + @"Orbit": @(NVActivityIndicatorTypeOrbit), |
| 36 | + @"AudioEqualizer": @(NVActivityIndicatorTypeAudioEqualizer), |
| 37 | + @"CircleStrokeSpin": @(NVActivityIndicatorTypeCircleStrokeSpin), |
| 38 | + @"BallDoubleBounce": @(NVActivityIndicatorTypeBallDoubleBounce) |
| 39 | +}; |
| 40 | + |
| 41 | +#ifdef RCT_NEW_ARCH_ENABLED |
2 | 42 |
|
3 | 43 | #import <react/renderer/components/LoaderKitViewSpec/ComponentDescriptors.h> |
4 | 44 | #import <react/renderer/components/LoaderKitViewSpec/EventEmitters.h> |
|
7 | 47 |
|
8 | 48 | #import "RCTFabricComponentsPlugins.h" |
9 | 49 |
|
10 | | -#import "NVActivityIndicatorView.h" |
11 | | -#import <React/RCTConvert.h> |
12 | | - |
13 | 50 | using namespace facebook::react; |
14 | 51 |
|
15 | 52 | @interface LoaderKitView () <RCTLoaderKitViewViewProtocol> |
@@ -70,50 +107,65 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & |
70 | 107 | - (NVActivityIndicatorType)getIndicatorTypeFromName:(NSString *)name |
71 | 108 | { |
72 | 109 | if (!name) return NVActivityIndicatorTypeBallPulse; |
| 110 | + |
| 111 | + NSNumber *typeNumber = nameToTypeMap[name]; |
| 112 | + if (typeNumber) { |
| 113 | + return (NVActivityIndicatorType)[typeNumber integerValue]; |
| 114 | + } |
73 | 115 |
|
74 | | - // Map indicator names to types (matching the Android names) |
75 | | - NSDictionary *nameToTypeMap = @{ |
76 | | - @"BallPulse": @(NVActivityIndicatorTypeBallPulse), |
77 | | - @"BallGridPulse": @(NVActivityIndicatorTypeBallGridPulse), |
78 | | - @"BallClipRotate": @(NVActivityIndicatorTypeBallClipRotate), |
79 | | - @"SquareSpin": @(NVActivityIndicatorTypeSquareSpin), |
80 | | - @"BallClipRotatePulse": @(NVActivityIndicatorTypeBallClipRotatePulse), |
81 | | - @"BallClipRotateMultiple": @(NVActivityIndicatorTypeBallClipRotateMultiple), |
82 | | - @"BallPulseRise": @(NVActivityIndicatorTypeBallPulseRise), |
83 | | - @"BallRotate": @(NVActivityIndicatorTypeBallRotate), |
84 | | - @"CubeTransition": @(NVActivityIndicatorTypeCubeTransition), |
85 | | - @"BallZigZag": @(NVActivityIndicatorTypeBallZigZag), |
86 | | - @"BallZigZagDeflect": @(NVActivityIndicatorTypeBallZigZagDeflect), |
87 | | - @"BallTrianglePath": @(NVActivityIndicatorTypeBallTrianglePath), |
88 | | - @"BallScale": @(NVActivityIndicatorTypeBallScale), |
89 | | - @"LineScale": @(NVActivityIndicatorTypeLineScale), |
90 | | - @"LineScaleParty": @(NVActivityIndicatorTypeLineScaleParty), |
91 | | - @"BallScaleMultiple": @(NVActivityIndicatorTypeBallScaleMultiple), |
92 | | - @"BallPulseSync": @(NVActivityIndicatorTypeBallPulseSync), |
93 | | - @"BallBeat": @(NVActivityIndicatorTypeBallBeat), |
94 | | - @"LineScalePulseOut": @(NVActivityIndicatorTypeLineScalePulseOut), |
95 | | - @"LineScalePulseOutRapid": @(NVActivityIndicatorTypeLineScalePulseOutRapid), |
96 | | - @"BallScaleRipple": @(NVActivityIndicatorTypeBallScaleRipple), |
97 | | - @"BallScaleRippleMultiple": @(NVActivityIndicatorTypeBallScaleRippleMultiple), |
98 | | - @"BallSpinFadeLoader": @(NVActivityIndicatorTypeBallSpinFadeLoader), |
99 | | - @"LineSpinFadeLoader": @(NVActivityIndicatorTypeLineSpinFadeLoader), |
100 | | - @"TriangleSkewSpin": @(NVActivityIndicatorTypeTriangleSkewSpin), |
101 | | - @"Pacman": @(NVActivityIndicatorTypePacman), |
102 | | - @"BallGridBeat": @(NVActivityIndicatorTypeBallGridBeat), |
103 | | - @"SemiCircleSpin": @(NVActivityIndicatorTypeSemiCircleSpin), |
104 | | - @"BallRotateChase": @(NVActivityIndicatorTypeBallRotateChase), |
105 | | - @"Orbit": @(NVActivityIndicatorTypeOrbit), |
106 | | - @"AudioEqualizer": @(NVActivityIndicatorTypeAudioEqualizer), |
107 | | - @"CircleStrokeSpin": @(NVActivityIndicatorTypeCircleStrokeSpin), |
108 | | - @"BallDoubleBounce": @(NVActivityIndicatorTypeBallDoubleBounce) |
109 | | - }; |
| 116 | + return NVActivityIndicatorTypeBallPulse; // Default fallback |
| 117 | +} |
| 118 | + |
| 119 | +@end |
| 120 | + |
| 121 | +#else |
| 122 | + |
| 123 | +@implementation LoaderKitViewManager |
| 124 | + |
| 125 | +RCT_EXPORT_MODULE(LoaderKitView) |
| 126 | + |
| 127 | +- (UIView *)view |
| 128 | +{ |
| 129 | + return [[NVActivityIndicatorView alloc] init]; |
| 130 | +} |
| 131 | + |
| 132 | +- (NVActivityIndicatorType)getIndicatorTypeFromName:(NSString *)name |
| 133 | +{ |
| 134 | + if (!name) return NVActivityIndicatorTypeBallPulse; |
110 | 135 |
|
111 | 136 | NSNumber *typeNumber = nameToTypeMap[name]; |
112 | 137 | if (typeNumber) { |
113 | 138 | return (NVActivityIndicatorType)[typeNumber integerValue]; |
114 | 139 | } |
115 | 140 |
|
116 | | - return NVActivityIndicatorTypeBallPulse; // Default fallback |
| 141 | + return NVActivityIndicatorTypeBallPulse; |
| 142 | +} |
| 143 | + |
| 144 | +RCT_CUSTOM_VIEW_PROPERTY(name, NSString, NVActivityIndicatorView) |
| 145 | +{ |
| 146 | + NSString *indicatorName = [RCTConvert NSString:json]; |
| 147 | + if (indicatorName) { |
| 148 | + NVActivityIndicatorType type = [self getIndicatorTypeFromName:indicatorName]; |
| 149 | + view.type = type; |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +RCT_CUSTOM_VIEW_PROPERTY(color, UIColor, NVActivityIndicatorView) |
| 154 | +{ |
| 155 | + UIColor *color = [RCTConvert UIColor:json]; |
| 156 | + if (color) { |
| 157 | + view.color = color; |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +RCT_CUSTOM_VIEW_PROPERTY(animationSpeedMultiplier, CGFloat, NVActivityIndicatorView) |
| 162 | +{ |
| 163 | + CGFloat speedMultiplier = [RCTConvert CGFloat:json]; |
| 164 | + view.animationSpeedMultiplier = speedMultiplier; |
117 | 165 | } |
118 | 166 |
|
119 | 167 | @end |
| 168 | + |
| 169 | +#endif |
| 170 | + |
| 171 | + |
0 commit comments