react-native-skeleton-native 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +104 -2
- 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 +79 -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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Moksh Upadhyay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# react-native-skeleton-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Skeleton and shimmer placeholders for React Native whose animation is drawn by the platform compositor (Core Animation on iOS, RenderThread on Android). The highlight keeps moving while the JavaScript thread and the UI thread are busy, because React never updates it.
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<img src="https://raw.githubusercontent.com/mokshupadhyay/react-native-skeleton-native/main/docs/screenshots/ios-shimmer.png" alt="Skeleton list on iOS, mid sweep" width="260" />
|
|
7
|
+
<img src="https://raw.githubusercontent.com/mokshupadhyay/react-native-skeleton-native/main/docs/screenshots/android-shimmer.png" alt="Skeleton list on Android, mid sweep" width="260" />
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
- **Native animation.** One sweep per group, started and driven natively. No `Animated` loop, no re-render per frame.
|
|
11
|
+
- **One highlight across many blocks.** `SkeletonGroup` shares one animation clock and one coordinate space, so a single band sweeps across every block inside it.
|
|
12
|
+
- **Follows the system.** Default colours switch with light and dark mode without a React re-render. The sweep direction follows RTL. Reduce Motion (iOS) and "Remove animations" (Android) are respected.
|
|
13
|
+
- **Accessible.** A group is one accessibility element with a label (`"Loading"` by default); the blocks inside are hidden from screen readers.
|
|
14
|
+
- **Typed, small API.** `Skeleton`, `Skeleton.Circle`, `Skeleton.Text`, `SkeletonGroup` and `Shimmer`.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install react-native-skeleton-native
|
|
20
|
+
cd ios && pod install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Requires React 18.2 or later and React Native 0.71 or later. It has native code, so you need a development build or a bare app; Expo Go cannot load it.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { Skeleton, SkeletonGroup } from 'react-native-skeleton-native';
|
|
29
|
+
|
|
30
|
+
function FeedPlaceholder() {
|
|
31
|
+
return (
|
|
32
|
+
<SkeletonGroup>
|
|
33
|
+
<View style={{ flexDirection: 'row', gap: 12 }}>
|
|
34
|
+
<Skeleton.Circle size={48} />
|
|
35
|
+
<View style={{ flex: 1 }}>
|
|
36
|
+
<Skeleton height={14} width="70%" />
|
|
37
|
+
<Skeleton.Text lines={2} />
|
|
38
|
+
</View>
|
|
39
|
+
</View>
|
|
40
|
+
</SkeletonGroup>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Wrap the blocks that should share one sweep in a `SkeletonGroup`. Animation props set on the group are inherited by everything inside, and any block can override them.
|
|
46
|
+
|
|
47
|
+
### Shimmer over your own content
|
|
48
|
+
|
|
49
|
+
`Shimmer` draws the moving highlight over arbitrary children, limited to the pixels they cover.
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { Shimmer } from 'react-native-skeleton-native';
|
|
53
|
+
|
|
54
|
+
<Shimmer duration={1800}>
|
|
55
|
+
<Image source={placeholder} style={{ width: 120, height: 120 }} />
|
|
56
|
+
</Shimmer>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Components
|
|
60
|
+
|
|
61
|
+
| Component | What it draws |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `Skeleton` | One block. `width` (number or percentage, default `'100%'`), `height` (default 16), `radius` (default 4). |
|
|
64
|
+
| `Skeleton.Circle` | A circle. `size` (default 40). |
|
|
65
|
+
| `Skeleton.Text` | Lines of text. `lines` (default 3), `lastLineWidth` (default `'60%'`), `lineHeight` (default 12), `gap` (default 8), `radius` (default 4). |
|
|
66
|
+
| `SkeletonGroup` | Shares one animation clock and coordinate space between its children, and is one accessibility element. |
|
|
67
|
+
| `Shimmer` | The moving highlight over your own children. Takes the animation props except `baseColor`. |
|
|
68
|
+
|
|
69
|
+
All of them also accept `style` and `testID`. `Skeleton`, `Skeleton.Circle`, `Skeleton.Text` and `SkeletonGroup` accept `accessibilityLabel`.
|
|
70
|
+
|
|
71
|
+
## Animation props
|
|
72
|
+
|
|
73
|
+
Shared by every component, and inheritable from a `SkeletonGroup`.
|
|
74
|
+
|
|
75
|
+
| Prop | Default | Notes |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| `variant` | `'shimmer'` | `'shimmer'`, `'pulse'` or `'none'`. |
|
|
78
|
+
| `duration` | `1400` | Milliseconds for one sweep or pulse. Clamped to 100 to 60000. |
|
|
79
|
+
| `direction` | `'auto'` | `'ltr'`, `'rtl'` or `'auto'` (follows `I18nManager.isRTL`). |
|
|
80
|
+
| `angle` | `20` | Lean of the highlight band in degrees, clamped to -45..45. |
|
|
81
|
+
| `baseColor` | theme grey | Block colour. |
|
|
82
|
+
| `highlightColor` | theme grey | Colour at the centre of the highlight. |
|
|
83
|
+
| `animated` | `true` | `false` pauses the animation and shows the static block. |
|
|
84
|
+
| `reduceMotion` | `'system'` | `'system'` follows the OS setting, `'always'` behaves as if it were on, `'never'` ignores it. |
|
|
85
|
+
|
|
86
|
+
Default colours: light `#E1E4E8` base and `#F5F7F9` highlight, dark `#2B2E33` base and `#3D4148` highlight. They are exported as `DEFAULT_COLORS`, with `DEFAULT_DURATION_MS`, `DEFAULT_ANGLE` and `DEFAULT_LABEL`.
|
|
87
|
+
|
|
88
|
+
Invalid values (a negative duration, an unknown variant) fall back to the default and log a warning in development builds.
|
|
89
|
+
|
|
90
|
+
## Status of version 0.1.0
|
|
91
|
+
|
|
92
|
+
The JavaScript has unit tests. The example app has been run on an Android emulator and an iOS simulator, which is where the screenshots above come from. Nothing has been run on a physical device yet, and I have not published measurements, so treat the "keeps moving while busy" behaviour as the design goal until you have checked it in your own app.
|
|
93
|
+
|
|
94
|
+
## Contributing
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
npm install
|
|
98
|
+
npm run check # typecheck, tests, build
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The `example/` folder is a React Native app that uses the packed library (`npm run example:install`).
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import groovy.json.JsonSlurper
|
|
2
|
+
|
|
3
|
+
def safeExtGet(prop, fallback) {
|
|
4
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Minor version of the app's React Native, or null when it cannot be found.
|
|
8
|
+
def reactNativeMinorVersion() {
|
|
9
|
+
def candidates = [
|
|
10
|
+
new File(projectDir, "../../react-native/package.json"),
|
|
11
|
+
new File(rootDir, "../node_modules/react-native/package.json"),
|
|
12
|
+
]
|
|
13
|
+
for (File file : candidates) {
|
|
14
|
+
if (!file.exists()) continue
|
|
15
|
+
def parts = new JsonSlurper().parseText(file.text).version.tokenize(".")
|
|
16
|
+
if (parts.size() < 2) return null
|
|
17
|
+
if (parts[0] != "0") return 1000
|
|
18
|
+
return parts[1].replaceAll("[^0-9].*", "").toInteger()
|
|
19
|
+
}
|
|
20
|
+
return null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def isNewArchitectureEnabled() {
|
|
24
|
+
def minor = reactNativeMinorVersion()
|
|
25
|
+
// React Native 0.82 removed the legacy architecture.
|
|
26
|
+
if (minor != null && minor >= 82) return true
|
|
27
|
+
def flag = project.findProperty("newArchEnabled") ?: project.findProperty("react.newArchEnabled")
|
|
28
|
+
return flag != null && flag.toString() == "true"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def supportsNamespace() {
|
|
32
|
+
try {
|
|
33
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize(".")
|
|
34
|
+
def major = parsed[0].toInteger()
|
|
35
|
+
def minor = parsed[1].toInteger()
|
|
36
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
37
|
+
} catch (Throwable ignored) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
apply plugin: "com.android.library"
|
|
43
|
+
|
|
44
|
+
if (isNewArchitectureEnabled()) {
|
|
45
|
+
apply plugin: "com.facebook.react"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
android {
|
|
49
|
+
if (supportsNamespace()) {
|
|
50
|
+
namespace "com.skeletonnative"
|
|
51
|
+
sourceSets {
|
|
52
|
+
main {
|
|
53
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
59
|
+
|
|
60
|
+
defaultConfig {
|
|
61
|
+
minSdkVersion safeExtGet("minSdkVersion", 24)
|
|
62
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
compileOptions {
|
|
66
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
67
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
sourceSets {
|
|
71
|
+
main {
|
|
72
|
+
if (isNewArchitectureEnabled()) {
|
|
73
|
+
java.srcDirs += ["src/newarch/java"]
|
|
74
|
+
} else {
|
|
75
|
+
java.srcDirs += ["src/oldarch/java"]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
repositories {
|
|
82
|
+
mavenCentral()
|
|
83
|
+
google()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dependencies {
|
|
87
|
+
// Resolved to react-android by the React Native Gradle plugin on 0.71+.
|
|
88
|
+
implementation "com.facebook.react:react-native:+"
|
|
89
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import android.os.SystemClock;
|
|
4
|
+
|
|
5
|
+
/** The time every skeleton outside a group measures its phase from. */
|
|
6
|
+
final class SkeletonEpoch {
|
|
7
|
+
static final long GLOBAL_MS = SystemClock.uptimeMillis();
|
|
8
|
+
|
|
9
|
+
private SkeletonEpoch() {}
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
5
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
6
|
+
|
|
7
|
+
@ReactModule(name = SkeletonGroupManager.NAME)
|
|
8
|
+
public class SkeletonGroupManager extends SkeletonGroupManagerSpec<SkeletonGroupView> {
|
|
9
|
+
public static final String NAME = "SkeletonNativeGroup";
|
|
10
|
+
|
|
11
|
+
@NonNull
|
|
12
|
+
@Override
|
|
13
|
+
public String getName() {
|
|
14
|
+
return NAME;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@NonNull
|
|
18
|
+
@Override
|
|
19
|
+
protected SkeletonGroupView createViewInstance(@NonNull ThemedReactContext context) {
|
|
20
|
+
return new SkeletonGroupView(context);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.os.SystemClock;
|
|
5
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Container for a group of skeletons. It holds the animation epoch that every
|
|
9
|
+
* skeleton and shimmer inside measures its phase from, and its size is the
|
|
10
|
+
* space the highlight sweeps across. Skeletons find it by walking up their
|
|
11
|
+
* parents, so it works on both architectures without any JS involvement.
|
|
12
|
+
*/
|
|
13
|
+
public class SkeletonGroupView extends ReactViewGroup {
|
|
14
|
+
final long epochMs = SystemClock.uptimeMillis();
|
|
15
|
+
|
|
16
|
+
public SkeletonGroupView(Context context) {
|
|
17
|
+
super(context);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.graphics.Canvas;
|
|
6
|
+
import android.graphics.drawable.AnimatedVectorDrawable;
|
|
7
|
+
import android.graphics.drawable.Drawable;
|
|
8
|
+
import android.view.View;
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import androidx.annotation.Nullable;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A tiny view (three periods of {@link #PERIOD_PX} px, {@link #HEIGHT_PX} px
|
|
14
|
+
* tall) that draws the AnimatedVectorDrawable. Its scale properties stretch
|
|
15
|
+
* it to the real size. RenderThread re-rasterizes an animating
|
|
16
|
+
* VectorDrawable into a bitmap on every frame at the size given by its bounds
|
|
17
|
+
* and the scale of the canvas it was recorded into; View scale properties are
|
|
18
|
+
* applied later, by the RenderNode, so the bitmap stays 300 x 2 px however
|
|
19
|
+
* big the skeleton is. It lives in the host's ViewGroupOverlay.
|
|
20
|
+
*/
|
|
21
|
+
@SuppressLint("ViewConstructor")
|
|
22
|
+
final class SkeletonHighlightView extends View {
|
|
23
|
+
static final int PERIOD_PX = 100;
|
|
24
|
+
static final int WIDTH_PX = 3 * PERIOD_PX;
|
|
25
|
+
static final int HEIGHT_PX = 2;
|
|
26
|
+
|
|
27
|
+
@Nullable private AnimatedVectorDrawable avd;
|
|
28
|
+
private float skewX;
|
|
29
|
+
|
|
30
|
+
SkeletonHighlightView(Context context) {
|
|
31
|
+
super(context);
|
|
32
|
+
setPivotX(0f);
|
|
33
|
+
setPivotY(0f);
|
|
34
|
+
setWillNotDraw(false);
|
|
35
|
+
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void setDrawable(@Nullable AnimatedVectorDrawable drawable) {
|
|
39
|
+
if (avd != null) avd.setCallback(null);
|
|
40
|
+
avd = drawable;
|
|
41
|
+
if (avd != null) {
|
|
42
|
+
avd.setCallback(this);
|
|
43
|
+
avd.setBounds(0, 0, WIDTH_PX, HEIGHT_PX);
|
|
44
|
+
}
|
|
45
|
+
invalidate();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void setSkewX(float value) {
|
|
49
|
+
if (value != skewX) {
|
|
50
|
+
skewX = value;
|
|
51
|
+
invalidate();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
protected void onDraw(@NonNull Canvas canvas) {
|
|
57
|
+
if (avd == null) return;
|
|
58
|
+
if (skewX != 0f) canvas.skew(skewX, 0f);
|
|
59
|
+
avd.draw(canvas);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Override
|
|
63
|
+
protected boolean verifyDrawable(@NonNull Drawable who) {
|
|
64
|
+
return who == avd || super.verifyDrawable(who);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import android.content.ContentResolver;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.database.ContentObserver;
|
|
6
|
+
import android.net.Uri;
|
|
7
|
+
import android.os.Handler;
|
|
8
|
+
import android.os.Looper;
|
|
9
|
+
import android.provider.Settings;
|
|
10
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Process-wide view of the system animation settings. Android has no separate
|
|
14
|
+
* "reduce motion" flag for apps: the accessibility setting "Remove animations"
|
|
15
|
+
* and the developer option both set {@code ANIMATOR_DURATION_SCALE} to 0, which
|
|
16
|
+
* disables every animator, including AnimatedVectorDrawable. A ContentObserver
|
|
17
|
+
* on that setting tells attached views when it changes.
|
|
18
|
+
*/
|
|
19
|
+
final class SkeletonMotion {
|
|
20
|
+
interface Listener {
|
|
21
|
+
void onMotionSettingsChanged();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private static final CopyOnWriteArrayList<Listener> LISTENERS = new CopyOnWriteArrayList<>();
|
|
25
|
+
private static ContentObserver observer;
|
|
26
|
+
|
|
27
|
+
private SkeletonMotion() {}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The setting itself is read rather than ValueAnimator.getDurationScale():
|
|
31
|
+
* the app process learns about a change asynchronously, after the
|
|
32
|
+
* ContentObserver has already fired, so ValueAnimator can lag by one change.
|
|
33
|
+
*/
|
|
34
|
+
static float durationScale(Context context) {
|
|
35
|
+
return settingsScale(context);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private static float settingsScale(Context context) {
|
|
39
|
+
try {
|
|
40
|
+
return Settings.Global.getFloat(context.getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, 1f);
|
|
41
|
+
} catch (RuntimeException e) {
|
|
42
|
+
return 1f;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static boolean animatorsEnabled(Context context) {
|
|
47
|
+
return settingsScale(context) != 0f;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static void addListener(Context context, Listener listener) {
|
|
51
|
+
LISTENERS.addIfAbsent(listener);
|
|
52
|
+
if (observer == null) {
|
|
53
|
+
final ContentResolver resolver = context.getApplicationContext().getContentResolver();
|
|
54
|
+
observer = new ContentObserver(new Handler(Looper.getMainLooper())) {
|
|
55
|
+
@Override
|
|
56
|
+
public void onChange(boolean selfChange) {
|
|
57
|
+
// AnimatedVectorDrawable scales durations by ValueAnimator's copy of the
|
|
58
|
+
// setting, which the process receives a little later; restart after it has.
|
|
59
|
+
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
|
60
|
+
@Override
|
|
61
|
+
public void run() {
|
|
62
|
+
for (Listener l : LISTENERS) l.onMotionSettingsChanged();
|
|
63
|
+
}
|
|
64
|
+
}, 250);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
Uri uri = Settings.Global.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
|
|
68
|
+
try {
|
|
69
|
+
resolver.registerContentObserver(uri, false, observer);
|
|
70
|
+
} catch (RuntimeException e) {
|
|
71
|
+
observer = null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static void removeListener(Listener listener) {
|
|
77
|
+
LISTENERS.remove(listener);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.facebook.react.ReactPackage;
|
|
5
|
+
import com.facebook.react.bridge.NativeModule;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
8
|
+
import java.util.Arrays;
|
|
9
|
+
import java.util.Collections;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
public class SkeletonNativePackage implements ReactPackage {
|
|
13
|
+
// Deprecated in recent React Native in favour of BaseReactPackage, which
|
|
14
|
+
// React Native 0.71-0.73 do not have. This package has no modules.
|
|
15
|
+
@NonNull
|
|
16
|
+
@Override
|
|
17
|
+
@SuppressWarnings("deprecation")
|
|
18
|
+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
19
|
+
return Collections.emptyList();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@NonNull
|
|
23
|
+
@Override
|
|
24
|
+
@SuppressWarnings("rawtypes")
|
|
25
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
26
|
+
return Arrays.<ViewManager>asList(new SkeletonViewManager(), new SkeletonGroupManager(), new SkeletonShimmerManager());
|
|
27
|
+
}
|
|
28
|
+
}
|