react-native-skeleton-native 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +89 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/skeletonnative/SkeletonEpoch.java +10 -0
- package/android/src/main/java/com/skeletonnative/SkeletonGroupManager.java +22 -0
- package/android/src/main/java/com/skeletonnative/SkeletonGroupView.java +19 -0
- package/android/src/main/java/com/skeletonnative/SkeletonHighlightView.java +66 -0
- package/android/src/main/java/com/skeletonnative/SkeletonMotion.java +81 -0
- package/android/src/main/java/com/skeletonnative/SkeletonNativePackage.java +28 -0
- package/android/src/main/java/com/skeletonnative/SkeletonPainter.java +418 -0
- package/android/src/main/java/com/skeletonnative/SkeletonResources.java +123 -0
- package/android/src/main/java/com/skeletonnative/SkeletonShimmerManager.java +72 -0
- package/android/src/main/java/com/skeletonnative/SkeletonShimmerView.java +74 -0
- package/android/src/main/java/com/skeletonnative/SkeletonView.java +81 -0
- package/android/src/main/java/com/skeletonnative/SkeletonViewManager.java +89 -0
- package/android/src/main/res/animator/skeleton_native_slide_1000.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1100.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1200.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1300.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1400.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1500.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1600.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1700.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1800.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_1900.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2000.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2100.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2200.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2300.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2400.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2500.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2600.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2700.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2800.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_2900.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_300.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3000.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3100.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3200.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3300.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3400.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3500.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3600.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3700.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3800.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_3900.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_400.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4000.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4100.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4200.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4300.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4400.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4500.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4600.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4700.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4800.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_4900.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_500.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_5000.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_600.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_700.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_800.xml +6 -0
- package/android/src/main/res/animator/skeleton_native_slide_900.xml +6 -0
- package/android/src/main/res/drawable/skeleton_native_pulse.xml +22 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_1900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_2900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_3900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_4900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_5000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_pulse_900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer.xml +22 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_1900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_2900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_3900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4100.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4200.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4300.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4400.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_4900.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_500.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_5000.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_600.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_700.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_800.xml +5 -0
- package/android/src/main/res/drawable/skeleton_native_shimmer_900.xml +5 -0
- package/android/src/newarch/java/com/skeletonnative/SkeletonGroupManagerSpec.java +19 -0
- package/android/src/newarch/java/com/skeletonnative/SkeletonShimmerManagerSpec.java +19 -0
- package/android/src/newarch/java/com/skeletonnative/SkeletonViewManagerSpec.java +19 -0
- package/android/src/oldarch/java/com/skeletonnative/SkeletonGroupManagerSpec.java +6 -0
- package/android/src/oldarch/java/com/skeletonnative/SkeletonShimmerManagerSpec.java +21 -0
- package/android/src/oldarch/java/com/skeletonnative/SkeletonViewManagerSpec.java +25 -0
- package/ios/RNSkeletonAnimator.h +75 -0
- package/ios/RNSkeletonAnimator.mm +406 -0
- package/ios/RNSkeletonComponentViews.mm +256 -0
- package/ios/RNSkeletonGroupRegistry.h +14 -0
- package/ios/RNSkeletonGroupRegistry.mm +37 -0
- package/ios/RNSkeletonLegacyViews.h +22 -0
- package/ios/RNSkeletonLegacyViews.mm +99 -0
- package/ios/RNSkeletonView.h +29 -0
- package/ios/RNSkeletonView.mm +77 -0
- package/ios/RNSkeletonViewManagers.mm +65 -0
- package/lib/commonjs/Shimmer.js +55 -0
- package/lib/commonjs/Skeleton.js +113 -0
- package/lib/commonjs/SkeletonGroup.js +58 -0
- package/lib/commonjs/context.js +10 -0
- package/lib/commonjs/index.js +15 -0
- package/lib/commonjs/props.js +113 -0
- package/lib/commonjs/specs/SkeletonNativeGroupNativeComponent.js +8 -0
- package/lib/commonjs/specs/SkeletonNativeShimmerNativeComponent.js +8 -0
- package/lib/commonjs/specs/SkeletonNativeViewNativeComponent.js +8 -0
- package/lib/commonjs/types.js +3 -0
- package/lib/module/Shimmer.js +16 -0
- package/lib/module/Skeleton.js +73 -0
- package/lib/module/SkeletonGroup.js +19 -0
- package/lib/module/context.js +6 -0
- package/lib/module/index.js +5 -0
- package/lib/module/props.js +103 -0
- package/lib/module/specs/SkeletonNativeGroupNativeComponent.js +3 -0
- package/lib/module/specs/SkeletonNativeShimmerNativeComponent.js +3 -0
- package/lib/module/specs/SkeletonNativeViewNativeComponent.js +3 -0
- package/lib/module/types.js +2 -0
- package/lib/typescript/Shimmer.d.ts +13 -0
- package/lib/typescript/Skeleton.d.ts +17 -0
- package/lib/typescript/SkeletonGroup.d.ts +17 -0
- package/lib/typescript/context.d.ts +7 -0
- package/lib/typescript/index.d.ts +7 -0
- package/lib/typescript/props.d.ts +42 -0
- package/lib/typescript/specs/SkeletonNativeGroupNativeComponent.d.ts +5 -0
- package/lib/typescript/specs/SkeletonNativeShimmerNativeComponent.d.ts +13 -0
- package/lib/typescript/specs/SkeletonNativeViewNativeComponent.d.ts +15 -0
- package/lib/typescript/types.d.ts +60 -0
- package/package.json +83 -4
- package/react-native-skeleton-native.podspec +20 -0
- package/react-native.config.js +10 -0
- package/src/Shimmer.tsx +38 -0
- package/src/Skeleton.tsx +125 -0
- package/src/SkeletonGroup.tsx +46 -0
- package/src/context.ts +13 -0
- package/src/index.ts +15 -0
- package/src/props.ts +126 -0
- package/src/specs/SkeletonNativeGroupNativeComponent.ts +9 -0
- package/src/specs/SkeletonNativeShimmerNativeComponent.ts +17 -0
- package/src/specs/SkeletonNativeViewNativeComponent.ts +20 -0
- package/src/types.ts +66 -0
- package/README.md +0 -3
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
#import "RNSkeletonAnimator.h"
|
|
2
|
+
|
|
3
|
+
static NSString *const kShimmerKey = @"rnskeleton.shimmer";
|
|
4
|
+
static NSString *const kPulseKey = @"rnskeleton.pulse";
|
|
5
|
+
|
|
6
|
+
/** Pattern period relative to the swept width: one third of each cycle has no band in view. */
|
|
7
|
+
static const CGFloat kPeriodFactor = 1.5;
|
|
8
|
+
static const CGFloat kGentleOpacity = 0.35;
|
|
9
|
+
static const CGFloat kPulseOpacity = 1.0;
|
|
10
|
+
/** Above any React Native subview layer (they use zPosition 0 unless zIndex is set). */
|
|
11
|
+
static const CGFloat kOverlayZ = 10000;
|
|
12
|
+
|
|
13
|
+
typedef NS_ENUM(NSInteger, RNSkeletonMode) {
|
|
14
|
+
RNSkeletonModeStatic,
|
|
15
|
+
RNSkeletonModeShimmer,
|
|
16
|
+
RNSkeletonModePulse,
|
|
17
|
+
RNSkeletonModeGentlePulse,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
static CFTimeInterval RNSkeletonGlobalEpoch(void)
|
|
21
|
+
{
|
|
22
|
+
static CFTimeInterval epoch;
|
|
23
|
+
static dispatch_once_t once;
|
|
24
|
+
dispatch_once(&once, ^{
|
|
25
|
+
epoch = CACurrentMediaTime();
|
|
26
|
+
});
|
|
27
|
+
return epoch;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static UIColor *RNSkeletonDynamic(UInt32 light, UInt32 dark)
|
|
31
|
+
{
|
|
32
|
+
UIColor * (^make)(UInt32) = ^UIColor *(UInt32 rgb) {
|
|
33
|
+
return [UIColor colorWithRed:((rgb >> 16) & 0xFF) / 255.0
|
|
34
|
+
green:((rgb >> 8) & 0xFF) / 255.0
|
|
35
|
+
blue:(rgb & 0xFF) / 255.0
|
|
36
|
+
alpha:1];
|
|
37
|
+
};
|
|
38
|
+
UIColor *lightColor = make(light);
|
|
39
|
+
UIColor *darkColor = make(dark);
|
|
40
|
+
if (@available(iOS 13.0, *)) {
|
|
41
|
+
return [UIColor colorWithDynamicProvider:^UIColor *(UITraitCollection *traits) {
|
|
42
|
+
return traits.userInterfaceStyle == UIUserInterfaceStyleDark ? darkColor : lightColor;
|
|
43
|
+
}];
|
|
44
|
+
}
|
|
45
|
+
return lightColor;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
UIColor *RNSkeletonDefaultBaseColor(void)
|
|
49
|
+
{
|
|
50
|
+
static UIColor *color;
|
|
51
|
+
static dispatch_once_t once;
|
|
52
|
+
dispatch_once(&once, ^{
|
|
53
|
+
color = RNSkeletonDynamic(0xE1E4E8, 0x2B2E33);
|
|
54
|
+
});
|
|
55
|
+
return color;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
UIColor *RNSkeletonDefaultHighlightColor(void)
|
|
59
|
+
{
|
|
60
|
+
static UIColor *color;
|
|
61
|
+
static dispatch_once_t once;
|
|
62
|
+
dispatch_once(&once, ^{
|
|
63
|
+
color = RNSkeletonDynamic(0xF5F7F9, 0x3D4148);
|
|
64
|
+
});
|
|
65
|
+
return color;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
RNSkeletonVariant RNSkeletonVariantFromString(NSString *value)
|
|
69
|
+
{
|
|
70
|
+
if ([value isEqualToString:@"pulse"]) return RNSkeletonVariantPulse;
|
|
71
|
+
if ([value isEqualToString:@"none"]) return RNSkeletonVariantNone;
|
|
72
|
+
return RNSkeletonVariantShimmer;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
RNSkeletonReduceMotion RNSkeletonReduceMotionFromString(NSString *value)
|
|
76
|
+
{
|
|
77
|
+
if ([value isEqualToString:@"always"]) return RNSkeletonReduceMotionAlways;
|
|
78
|
+
if ([value isEqualToString:@"never"]) return RNSkeletonReduceMotionNever;
|
|
79
|
+
return RNSkeletonReduceMotionSystem;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@implementation RNSkeletonAnimator {
|
|
83
|
+
__weak UIView *_host;
|
|
84
|
+
BOOL _overlay;
|
|
85
|
+
CALayer *_container;
|
|
86
|
+
CALayer *_transformLayer;
|
|
87
|
+
CAGradientLayer *_gradient;
|
|
88
|
+
CALayer *_pulse;
|
|
89
|
+
CALayer *_mask;
|
|
90
|
+
__weak UIView<RNSkeletonGroupHost> *_group;
|
|
91
|
+
NSString *_animationKey;
|
|
92
|
+
BOOL _inBackground;
|
|
93
|
+
BOOL _snapshotScheduled;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
- (instancetype)initWithHost:(UIView *)host overlay:(BOOL)overlay
|
|
97
|
+
{
|
|
98
|
+
if (self = [super init]) {
|
|
99
|
+
_host = host;
|
|
100
|
+
_overlay = overlay;
|
|
101
|
+
_durationMs = 1400;
|
|
102
|
+
_angle = 20;
|
|
103
|
+
_animated = YES;
|
|
104
|
+
_variant = RNSkeletonVariantShimmer;
|
|
105
|
+
_reduceMotion = RNSkeletonReduceMotionSystem;
|
|
106
|
+
|
|
107
|
+
_container = [CALayer layer];
|
|
108
|
+
_container.masksToBounds = YES;
|
|
109
|
+
_container.hidden = YES;
|
|
110
|
+
if (overlay) {
|
|
111
|
+
_container.zPosition = kOverlayZ;
|
|
112
|
+
_mask = [CALayer layer];
|
|
113
|
+
_container.mask = _mask;
|
|
114
|
+
}
|
|
115
|
+
_transformLayer = [CALayer layer];
|
|
116
|
+
_transformLayer.anchorPoint = CGPointZero;
|
|
117
|
+
_transformLayer.position = CGPointZero;
|
|
118
|
+
_transformLayer.bounds = CGRectZero;
|
|
119
|
+
_gradient = [CAGradientLayer layer];
|
|
120
|
+
_gradient.startPoint = CGPointMake(0, 0.5);
|
|
121
|
+
_gradient.endPoint = CGPointMake(1, 0.5);
|
|
122
|
+
[_transformLayer addSublayer:_gradient];
|
|
123
|
+
_pulse = [CALayer layer];
|
|
124
|
+
[_container addSublayer:_transformLayer];
|
|
125
|
+
[_container addSublayer:_pulse];
|
|
126
|
+
[host.layer addSublayer:_container];
|
|
127
|
+
|
|
128
|
+
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
|
129
|
+
[center addObserver:self
|
|
130
|
+
selector:@selector(reduceMotionChanged)
|
|
131
|
+
name:UIAccessibilityReduceMotionStatusDidChangeNotification
|
|
132
|
+
object:nil];
|
|
133
|
+
[center addObserver:self
|
|
134
|
+
selector:@selector(didEnterBackground)
|
|
135
|
+
name:UIApplicationDidEnterBackgroundNotification
|
|
136
|
+
object:nil];
|
|
137
|
+
[center addObserver:self
|
|
138
|
+
selector:@selector(willEnterForeground)
|
|
139
|
+
name:UIApplicationWillEnterForegroundNotification
|
|
140
|
+
object:nil];
|
|
141
|
+
}
|
|
142
|
+
return self;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
- (void)dealloc
|
|
146
|
+
{
|
|
147
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
148
|
+
UIView *host = _host;
|
|
149
|
+
if (host) [_group skeletonRemoveMember:host];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#pragma mark - Notifications
|
|
153
|
+
|
|
154
|
+
- (void)reduceMotionChanged
|
|
155
|
+
{
|
|
156
|
+
[self update];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
- (void)didEnterBackground
|
|
160
|
+
{
|
|
161
|
+
_inBackground = YES;
|
|
162
|
+
[self removeAnimations];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
- (void)willEnterForeground
|
|
166
|
+
{
|
|
167
|
+
_inBackground = NO;
|
|
168
|
+
[self update];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#pragma mark - Mode and colours
|
|
172
|
+
|
|
173
|
+
- (RNSkeletonMode)mode
|
|
174
|
+
{
|
|
175
|
+
if (!_animated || _variant == RNSkeletonVariantNone) return RNSkeletonModeStatic;
|
|
176
|
+
BOOL reduced = _reduceMotion == RNSkeletonReduceMotionAlways ||
|
|
177
|
+
(_reduceMotion == RNSkeletonReduceMotionSystem && UIAccessibilityIsReduceMotionEnabled());
|
|
178
|
+
if (reduced) return RNSkeletonModeGentlePulse;
|
|
179
|
+
return _variant == RNSkeletonVariantPulse ? RNSkeletonModePulse : RNSkeletonModeShimmer;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
- (UIColor *)resolvedHighlight
|
|
183
|
+
{
|
|
184
|
+
UIColor *color = _highlightColor ?: RNSkeletonDefaultHighlightColor();
|
|
185
|
+
UIView *host = _host;
|
|
186
|
+
if (@available(iOS 13.0, *)) {
|
|
187
|
+
if (host) color = [color resolvedColorWithTraitCollection:host.traitCollection];
|
|
188
|
+
}
|
|
189
|
+
return color;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
- (BOOL)isAnimating
|
|
193
|
+
{
|
|
194
|
+
return [_gradient animationForKey:kShimmerKey] != nil || [_pulse animationForKey:kPulseKey] != nil;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#pragma mark - Lifecycle
|
|
198
|
+
|
|
199
|
+
- (void)hostDidMoveToWindow
|
|
200
|
+
{
|
|
201
|
+
UIView *host = _host;
|
|
202
|
+
if (!host) return;
|
|
203
|
+
if (host.window) {
|
|
204
|
+
[self findGroup];
|
|
205
|
+
[self update];
|
|
206
|
+
if (_overlay) [self setNeedsSnapshot];
|
|
207
|
+
} else {
|
|
208
|
+
// Core Animation drops a layer's animations when it leaves the window; take
|
|
209
|
+
// them off explicitly so update re-adds them (at the epoch phase) on return.
|
|
210
|
+
[self removeAnimations];
|
|
211
|
+
[_group skeletonRemoveMember:host];
|
|
212
|
+
_group = nil;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
- (void)hostDidLayout
|
|
217
|
+
{
|
|
218
|
+
[self update];
|
|
219
|
+
if (_overlay) [self setNeedsSnapshot];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
- (void)hostTraitsDidChange
|
|
223
|
+
{
|
|
224
|
+
[self update];
|
|
225
|
+
if (_overlay) [self setNeedsSnapshot];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
- (void)findGroup
|
|
229
|
+
{
|
|
230
|
+
UIView *host = _host;
|
|
231
|
+
UIView<RNSkeletonGroupHost> *found = nil;
|
|
232
|
+
for (UIView *v = host.superview; v != nil; v = v.superview) {
|
|
233
|
+
if ([v conformsToProtocol:@protocol(RNSkeletonGroupHost)]) {
|
|
234
|
+
found = (UIView<RNSkeletonGroupHost> *)v;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (found != _group) {
|
|
239
|
+
[_group skeletonRemoveMember:host];
|
|
240
|
+
_group = found;
|
|
241
|
+
[found skeletonAddMember:host];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
- (void)removeAnimations
|
|
246
|
+
{
|
|
247
|
+
[_gradient removeAnimationForKey:kShimmerKey];
|
|
248
|
+
[_pulse removeAnimationForKey:kPulseKey];
|
|
249
|
+
_animationKey = nil;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#pragma mark - Geometry and animations
|
|
253
|
+
|
|
254
|
+
- (void)update
|
|
255
|
+
{
|
|
256
|
+
UIView *host = _host;
|
|
257
|
+
if (!host) return;
|
|
258
|
+
[CATransaction begin];
|
|
259
|
+
[CATransaction setDisableActions:YES];
|
|
260
|
+
[self applyWithHost:host];
|
|
261
|
+
[CATransaction commit];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
- (void)applyWithHost:(UIView *)host
|
|
265
|
+
{
|
|
266
|
+
CGRect bounds = host.bounds;
|
|
267
|
+
CGFloat w = bounds.size.width;
|
|
268
|
+
CGFloat h = bounds.size.height;
|
|
269
|
+
RNSkeletonMode mode = [self mode];
|
|
270
|
+
_container.frame = bounds;
|
|
271
|
+
if (_overlay) _mask.frame = bounds;
|
|
272
|
+
|
|
273
|
+
BOOL visible = mode != RNSkeletonModeStatic && w > 0 && h > 0;
|
|
274
|
+
_container.hidden = !visible;
|
|
275
|
+
if (!visible || host.window == nil || _inBackground) {
|
|
276
|
+
[self removeAnimations];
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
UIView *group = _group;
|
|
281
|
+
CGFloat ox = 0, oy = 0, gw = w, gh = h;
|
|
282
|
+
if (group) {
|
|
283
|
+
CGPoint origin = [host convertPoint:CGPointZero toView:group];
|
|
284
|
+
ox = origin.x;
|
|
285
|
+
oy = origin.y;
|
|
286
|
+
gw = MAX(group.bounds.size.width, 1);
|
|
287
|
+
gh = MAX(group.bounds.size.height, 1);
|
|
288
|
+
}
|
|
289
|
+
CFTimeInterval epoch = group ? [(id<RNSkeletonGroupHost>)group skeletonEpoch] : RNSkeletonGlobalEpoch();
|
|
290
|
+
CGColorRef high = [self resolvedHighlight].CGColor;
|
|
291
|
+
CGColorRef clear = [[self resolvedHighlight] colorWithAlphaComponent:0].CGColor;
|
|
292
|
+
CFTimeInterval duration = MAX(_durationMs, 100) / 1000.0;
|
|
293
|
+
|
|
294
|
+
if (mode == RNSkeletonModeShimmer) {
|
|
295
|
+
_pulse.hidden = YES;
|
|
296
|
+
[_pulse removeAnimationForKey:kPulseKey];
|
|
297
|
+
_transformLayer.hidden = NO;
|
|
298
|
+
|
|
299
|
+
CGFloat tanA = tan(_angle * M_PI / 180.0);
|
|
300
|
+
CGFloat period = MAX(1, MAX(kPeriodFactor * gw, kPeriodFactor * fabs(tanA) * gh));
|
|
301
|
+
CGFloat oxm = _rtl ? gw - ox - w : ox;
|
|
302
|
+
CGFloat s = _rtl ? -1 : 1;
|
|
303
|
+
CGFloat c = _rtl ? gw : 0;
|
|
304
|
+
// Maps the (mirrored, unskewed) group space of the gradient into host
|
|
305
|
+
// coordinates: x = s*(u + tan*(v - gh/2)) + c - ox, y = v - oy.
|
|
306
|
+
CATransform3D t = CATransform3DIdentity;
|
|
307
|
+
t.m11 = s;
|
|
308
|
+
t.m21 = s * tanA;
|
|
309
|
+
t.m41 = c - ox - s * tanA * gh / 2;
|
|
310
|
+
t.m42 = -oy;
|
|
311
|
+
_transformLayer.transform = t;
|
|
312
|
+
|
|
313
|
+
// Left edge a multiple of the period, 1.5-2.5 periods left of the host,
|
|
314
|
+
// so a translation of up to one period always covers it with margin.
|
|
315
|
+
CGFloat left = ceil((oxm - 2.5 * period) / period) * period;
|
|
316
|
+
_gradient.frame = CGRectMake(left, oy, 4 * period, h);
|
|
317
|
+
NSMutableArray *colors = [NSMutableArray array];
|
|
318
|
+
NSMutableArray<NSNumber *> *locations = [NSMutableArray array];
|
|
319
|
+
[colors addObject:(__bridge id)clear];
|
|
320
|
+
[locations addObject:@0];
|
|
321
|
+
for (int k = 0; k < 4; k++) {
|
|
322
|
+
[colors addObjectsFromArray:@[ (__bridge id)clear, (__bridge id)high, (__bridge id)clear ]];
|
|
323
|
+
[locations addObjectsFromArray:@[ @((k + 0.36) / 4), @((k + 0.5) / 4), @((k + 0.64) / 4) ]];
|
|
324
|
+
}
|
|
325
|
+
[colors addObject:(__bridge id)clear];
|
|
326
|
+
[locations addObject:@1];
|
|
327
|
+
_gradient.colors = colors;
|
|
328
|
+
_gradient.locations = locations;
|
|
329
|
+
|
|
330
|
+
NSString *key = [NSString stringWithFormat:@"s|%.3f|%.4f|%.6f", period, duration, epoch];
|
|
331
|
+
if (![key isEqualToString:_animationKey] || [_gradient animationForKey:kShimmerKey] == nil) {
|
|
332
|
+
CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
|
|
333
|
+
a.fromValue = @0;
|
|
334
|
+
a.toValue = @(period);
|
|
335
|
+
a.duration = duration;
|
|
336
|
+
a.repeatCount = HUGE_VALF;
|
|
337
|
+
a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
|
|
338
|
+
a.removedOnCompletion = NO;
|
|
339
|
+
// A beginTime at the shared epoch puts every view of the group in phase.
|
|
340
|
+
a.beginTime = [_gradient convertTime:epoch fromLayer:nil];
|
|
341
|
+
[_gradient addAnimation:a forKey:kShimmerKey];
|
|
342
|
+
_animationKey = key;
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
_transformLayer.hidden = YES;
|
|
346
|
+
[_gradient removeAnimationForKey:kShimmerKey];
|
|
347
|
+
_pulse.hidden = NO;
|
|
348
|
+
_pulse.frame = bounds;
|
|
349
|
+
_pulse.backgroundColor = high;
|
|
350
|
+
_pulse.opacity = 0;
|
|
351
|
+
BOOL gentle = mode == RNSkeletonModeGentlePulse;
|
|
352
|
+
CFTimeInterval half = gentle ? duration : duration / 2;
|
|
353
|
+
CGFloat peak = gentle ? kGentleOpacity : kPulseOpacity;
|
|
354
|
+
NSString *key = [NSString stringWithFormat:@"p|%.4f|%.2f|%.6f", half, peak, epoch];
|
|
355
|
+
if (![key isEqualToString:_animationKey] || [_pulse animationForKey:kPulseKey] == nil) {
|
|
356
|
+
CABasicAnimation *a = [CABasicAnimation animationWithKeyPath:@"opacity"];
|
|
357
|
+
a.fromValue = @0;
|
|
358
|
+
a.toValue = @(peak);
|
|
359
|
+
a.duration = half;
|
|
360
|
+
a.autoreverses = YES;
|
|
361
|
+
a.repeatCount = HUGE_VALF;
|
|
362
|
+
a.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
|
|
363
|
+
a.removedOnCompletion = NO;
|
|
364
|
+
a.beginTime = [_pulse convertTime:epoch fromLayer:nil];
|
|
365
|
+
[_pulse addAnimation:a forKey:kPulseKey];
|
|
366
|
+
_animationKey = key;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
#pragma mark - Overlay mask
|
|
372
|
+
|
|
373
|
+
- (void)setNeedsSnapshot
|
|
374
|
+
{
|
|
375
|
+
if (!_overlay || _snapshotScheduled) return;
|
|
376
|
+
_snapshotScheduled = YES;
|
|
377
|
+
// Next run loop turn, after the children of this layout pass have been laid out.
|
|
378
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
379
|
+
self->_snapshotScheduled = NO;
|
|
380
|
+
[self takeSnapshot];
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
- (void)takeSnapshot
|
|
385
|
+
{
|
|
386
|
+
UIView *host = _host;
|
|
387
|
+
if (!host || host.window == nil || _container.hidden) return;
|
|
388
|
+
CGRect bounds = host.bounds;
|
|
389
|
+
if (bounds.size.width <= 0 || bounds.size.height <= 0) return;
|
|
390
|
+
[CATransaction begin];
|
|
391
|
+
[CATransaction setDisableActions:YES];
|
|
392
|
+
_container.hidden = YES;
|
|
393
|
+
UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat preferredFormat];
|
|
394
|
+
format.opaque = NO;
|
|
395
|
+
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithBounds:bounds format:format];
|
|
396
|
+
UIImage *image = [renderer imageWithActions:^(UIGraphicsImageRendererContext *ctx) {
|
|
397
|
+
[host.layer renderInContext:ctx.CGContext];
|
|
398
|
+
}];
|
|
399
|
+
_container.hidden = NO;
|
|
400
|
+
_mask.frame = bounds;
|
|
401
|
+
_mask.contents = (__bridge id)image.CGImage;
|
|
402
|
+
_mask.contentsScale = image.scale;
|
|
403
|
+
[CATransaction commit];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
@end
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
// New Architecture (Fabric) component views. The old architecture uses the
|
|
2
|
+
// view managers in RNSkeletonViewManagers.mm instead.
|
|
3
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
4
|
+
|
|
5
|
+
#import <React/RCTConversions.h>
|
|
6
|
+
#import <React/RCTViewComponentView.h>
|
|
7
|
+
|
|
8
|
+
#import <react/renderer/components/RNSkeletonNativeSpec/ComponentDescriptors.h>
|
|
9
|
+
#import <react/renderer/components/RNSkeletonNativeSpec/Props.h>
|
|
10
|
+
#import <react/renderer/components/RNSkeletonNativeSpec/RCTComponentViewHelpers.h>
|
|
11
|
+
|
|
12
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
13
|
+
#import "RNSkeletonAnimator.h"
|
|
14
|
+
#import "RNSkeletonGroupRegistry.h"
|
|
15
|
+
#import "RNSkeletonView.h"
|
|
16
|
+
|
|
17
|
+
using namespace facebook::react;
|
|
18
|
+
|
|
19
|
+
static UIColor *_Nullable RNSkeletonColor(const SharedColor &color)
|
|
20
|
+
{
|
|
21
|
+
return color ? RCTUIColorFromSharedColor(color) : nil;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#pragma mark - SkeletonNativeView
|
|
25
|
+
|
|
26
|
+
@interface RNSkeletonNativeComponentView : RCTViewComponentView <RCTSkeletonNativeViewViewProtocol>
|
|
27
|
+
@end
|
|
28
|
+
|
|
29
|
+
@implementation RNSkeletonNativeComponentView {
|
|
30
|
+
RNSkeletonView *_view;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
34
|
+
{
|
|
35
|
+
return concreteComponentDescriptorProvider<SkeletonNativeViewComponentDescriptor>();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
39
|
+
{
|
|
40
|
+
if (self = [super initWithFrame:frame]) {
|
|
41
|
+
static const auto defaultProps = std::make_shared<const SkeletonNativeViewProps>();
|
|
42
|
+
_props = defaultProps;
|
|
43
|
+
_view = [[RNSkeletonView alloc] initWithFrame:self.bounds];
|
|
44
|
+
self.contentView = _view;
|
|
45
|
+
}
|
|
46
|
+
return self;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
50
|
+
{
|
|
51
|
+
const auto &p = *std::static_pointer_cast<SkeletonNativeViewProps const>(props);
|
|
52
|
+
_view.baseColor = RNSkeletonColor(p.baseColor);
|
|
53
|
+
_view.highlightColor = RNSkeletonColor(p.highlightColor);
|
|
54
|
+
_view.duration = p.duration;
|
|
55
|
+
_view.direction = p.direction == SkeletonNativeViewDirection::Rtl ? @"rtl" : @"ltr";
|
|
56
|
+
_view.angle = p.angle;
|
|
57
|
+
switch (p.variant) {
|
|
58
|
+
case SkeletonNativeViewVariant::Pulse:
|
|
59
|
+
_view.variant = @"pulse";
|
|
60
|
+
break;
|
|
61
|
+
case SkeletonNativeViewVariant::None:
|
|
62
|
+
_view.variant = @"none";
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
_view.variant = @"shimmer";
|
|
66
|
+
}
|
|
67
|
+
_view.animated = p.animated;
|
|
68
|
+
switch (p.reduceMotion) {
|
|
69
|
+
case SkeletonNativeViewReduceMotion::Always:
|
|
70
|
+
_view.reduceMotion = @"always";
|
|
71
|
+
break;
|
|
72
|
+
case SkeletonNativeViewReduceMotion::Never:
|
|
73
|
+
_view.reduceMotion = @"never";
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
_view.reduceMotion = @"system";
|
|
77
|
+
}
|
|
78
|
+
_view.cornerRadius = p.cornerRadius;
|
|
79
|
+
[super updateProps:props oldProps:oldProps];
|
|
80
|
+
[_view commitProps];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@end
|
|
84
|
+
|
|
85
|
+
// C linkage, as the generated component provider of React Native 0.71-0.76 expects.
|
|
86
|
+
extern "C" Class<RCTComponentViewProtocol> SkeletonNativeViewCls(void);
|
|
87
|
+
|
|
88
|
+
Class<RCTComponentViewProtocol> SkeletonNativeViewCls(void)
|
|
89
|
+
{
|
|
90
|
+
return RNSkeletonNativeComponentView.class;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#pragma mark - SkeletonNativeGroup
|
|
94
|
+
|
|
95
|
+
@interface RNSkeletonGroupComponentView : RCTViewComponentView <RCTSkeletonNativeGroupViewProtocol, RNSkeletonGroupHost>
|
|
96
|
+
@end
|
|
97
|
+
|
|
98
|
+
@implementation RNSkeletonGroupComponentView {
|
|
99
|
+
RNSkeletonGroupRegistry *_registry;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
103
|
+
{
|
|
104
|
+
return concreteComponentDescriptorProvider<SkeletonNativeGroupComponentDescriptor>();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
108
|
+
{
|
|
109
|
+
if (self = [super initWithFrame:frame]) {
|
|
110
|
+
static const auto defaultProps = std::make_shared<const SkeletonNativeGroupProps>();
|
|
111
|
+
_props = defaultProps;
|
|
112
|
+
_registry = [RNSkeletonGroupRegistry new];
|
|
113
|
+
}
|
|
114
|
+
return self;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
- (void)prepareForRecycle
|
|
118
|
+
{
|
|
119
|
+
[super prepareForRecycle];
|
|
120
|
+
// A recycled group is a new group: give it a new epoch.
|
|
121
|
+
_registry = [RNSkeletonGroupRegistry new];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
- (CFTimeInterval)skeletonEpoch
|
|
125
|
+
{
|
|
126
|
+
return _registry.epoch;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
- (void)skeletonAddMember:(UIView *)member
|
|
130
|
+
{
|
|
131
|
+
[_registry add:member];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
- (void)skeletonRemoveMember:(UIView *)member
|
|
135
|
+
{
|
|
136
|
+
[_registry remove:member];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (void)layoutSubviews
|
|
140
|
+
{
|
|
141
|
+
[super layoutSubviews];
|
|
142
|
+
[_registry groupDidLayout];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@end
|
|
146
|
+
|
|
147
|
+
// C linkage, as the generated component provider of React Native 0.71-0.76 expects.
|
|
148
|
+
extern "C" Class<RCTComponentViewProtocol> SkeletonNativeGroupCls(void);
|
|
149
|
+
|
|
150
|
+
Class<RCTComponentViewProtocol> SkeletonNativeGroupCls(void)
|
|
151
|
+
{
|
|
152
|
+
return RNSkeletonGroupComponentView.class;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#pragma mark - SkeletonNativeShimmer
|
|
156
|
+
|
|
157
|
+
@interface RNSkeletonShimmerComponentView : RCTViewComponentView <RCTSkeletonNativeShimmerViewProtocol, RNSkeletonMember>
|
|
158
|
+
@end
|
|
159
|
+
|
|
160
|
+
@implementation RNSkeletonShimmerComponentView {
|
|
161
|
+
RNSkeletonAnimator *_animator;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
165
|
+
{
|
|
166
|
+
return concreteComponentDescriptorProvider<SkeletonNativeShimmerComponentDescriptor>();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
170
|
+
{
|
|
171
|
+
if (self = [super initWithFrame:frame]) {
|
|
172
|
+
static const auto defaultProps = std::make_shared<const SkeletonNativeShimmerProps>();
|
|
173
|
+
_props = defaultProps;
|
|
174
|
+
_animator = [[RNSkeletonAnimator alloc] initWithHost:self overlay:YES];
|
|
175
|
+
}
|
|
176
|
+
return self;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
|
180
|
+
{
|
|
181
|
+
const auto &p = *std::static_pointer_cast<SkeletonNativeShimmerProps const>(props);
|
|
182
|
+
_animator.highlightColor = RNSkeletonColor(p.highlightColor);
|
|
183
|
+
_animator.durationMs = p.duration;
|
|
184
|
+
_animator.rtl = p.direction == SkeletonNativeShimmerDirection::Rtl;
|
|
185
|
+
_animator.angle = MAX(-45, MIN(45, p.angle));
|
|
186
|
+
switch (p.variant) {
|
|
187
|
+
case SkeletonNativeShimmerVariant::Pulse:
|
|
188
|
+
_animator.variant = RNSkeletonVariantPulse;
|
|
189
|
+
break;
|
|
190
|
+
case SkeletonNativeShimmerVariant::None:
|
|
191
|
+
_animator.variant = RNSkeletonVariantNone;
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
_animator.variant = RNSkeletonVariantShimmer;
|
|
195
|
+
}
|
|
196
|
+
_animator.animated = p.animated;
|
|
197
|
+
switch (p.reduceMotion) {
|
|
198
|
+
case SkeletonNativeShimmerReduceMotion::Always:
|
|
199
|
+
_animator.reduceMotion = RNSkeletonReduceMotionAlways;
|
|
200
|
+
break;
|
|
201
|
+
case SkeletonNativeShimmerReduceMotion::Never:
|
|
202
|
+
_animator.reduceMotion = RNSkeletonReduceMotionNever;
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
_animator.reduceMotion = RNSkeletonReduceMotionSystem;
|
|
206
|
+
}
|
|
207
|
+
[super updateProps:props oldProps:oldProps];
|
|
208
|
+
[_animator update];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
212
|
+
{
|
|
213
|
+
[super mountChildComponentView:childComponentView index:index];
|
|
214
|
+
[_animator setNeedsSnapshot];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
218
|
+
{
|
|
219
|
+
[super unmountChildComponentView:childComponentView index:index];
|
|
220
|
+
[_animator setNeedsSnapshot];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
- (void)layoutSubviews
|
|
224
|
+
{
|
|
225
|
+
[super layoutSubviews];
|
|
226
|
+
[_animator hostDidLayout];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
- (void)didMoveToWindow
|
|
230
|
+
{
|
|
231
|
+
[super didMoveToWindow];
|
|
232
|
+
[_animator hostDidMoveToWindow];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
|
|
236
|
+
{
|
|
237
|
+
[super traitCollectionDidChange:previousTraitCollection];
|
|
238
|
+
[_animator hostTraitsDidChange];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
- (void)skeletonGroupDidLayout
|
|
242
|
+
{
|
|
243
|
+
[_animator hostDidLayout];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@end
|
|
247
|
+
|
|
248
|
+
// C linkage, as the generated component provider of React Native 0.71-0.76 expects.
|
|
249
|
+
extern "C" Class<RCTComponentViewProtocol> SkeletonNativeShimmerCls(void);
|
|
250
|
+
|
|
251
|
+
Class<RCTComponentViewProtocol> SkeletonNativeShimmerCls(void)
|
|
252
|
+
{
|
|
253
|
+
return RNSkeletonShimmerComponentView.class;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
#endif
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
/** Members of one group, held weakly; shared by both architectures' group views. */
|
|
6
|
+
@interface RNSkeletonGroupRegistry : NSObject
|
|
7
|
+
@property (nonatomic, readonly) CFTimeInterval epoch;
|
|
8
|
+
- (void)add:(UIView *)member;
|
|
9
|
+
- (void)remove:(UIView *)member;
|
|
10
|
+
/** Tell every member that the group's layout changed. */
|
|
11
|
+
- (void)groupDidLayout;
|
|
12
|
+
@end
|
|
13
|
+
|
|
14
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import "RNSkeletonGroupRegistry.h"
|
|
2
|
+
#import <QuartzCore/QuartzCore.h>
|
|
3
|
+
#import "RNSkeletonAnimator.h"
|
|
4
|
+
|
|
5
|
+
@implementation RNSkeletonGroupRegistry {
|
|
6
|
+
NSHashTable<UIView *> *_members;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
- (instancetype)init
|
|
10
|
+
{
|
|
11
|
+
if (self = [super init]) {
|
|
12
|
+
_epoch = CACurrentMediaTime();
|
|
13
|
+
_members = [NSHashTable weakObjectsHashTable];
|
|
14
|
+
}
|
|
15
|
+
return self;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
- (void)add:(UIView *)member
|
|
19
|
+
{
|
|
20
|
+
[_members addObject:member];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (void)remove:(UIView *)member
|
|
24
|
+
{
|
|
25
|
+
[_members removeObject:member];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (void)groupDidLayout
|
|
29
|
+
{
|
|
30
|
+
for (UIView *member in _members.allObjects) {
|
|
31
|
+
if ([member conformsToProtocol:@protocol(RNSkeletonMember)]) {
|
|
32
|
+
[(id<RNSkeletonMember>)member skeletonGroupDidLayout];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@end
|