react-native-skeleton-native 0.1.0 → 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 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 ADDED
@@ -0,0 +1,105 @@
1
+ # react-native-skeleton-native
2
+
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
@@ -1,11 +1,9 @@
1
1
  package com.skeletonnative;
2
2
 
3
- import android.animation.ValueAnimator;
4
3
  import android.content.ContentResolver;
5
4
  import android.content.Context;
6
5
  import android.database.ContentObserver;
7
6
  import android.net.Uri;
8
- import android.os.Build;
9
7
  import android.os.Handler;
10
8
  import android.os.Looper;
11
9
  import android.provider.Settings;
@@ -28,10 +26,12 @@ final class SkeletonMotion {
28
26
 
29
27
  private SkeletonMotion() {}
30
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
+ */
31
34
  static float durationScale(Context context) {
32
- if (Build.VERSION.SDK_INT >= 26) {
33
- return ValueAnimator.getDurationScale();
34
- }
35
35
  return settingsScale(context);
36
36
  }
37
37
 
@@ -44,9 +44,6 @@ final class SkeletonMotion {
44
44
  }
45
45
 
46
46
  static boolean animatorsEnabled(Context context) {
47
- if (Build.VERSION.SDK_INT >= 26) {
48
- return ValueAnimator.areAnimatorsEnabled();
49
- }
50
47
  return settingsScale(context) != 0f;
51
48
  }
52
49
 
@@ -57,13 +54,14 @@ final class SkeletonMotion {
57
54
  observer = new ContentObserver(new Handler(Looper.getMainLooper())) {
58
55
  @Override
59
56
  public void onChange(boolean selfChange) {
60
- // ValueAnimator reads the new scale on the main thread; post so it has.
61
- new Handler(Looper.getMainLooper()).post(new Runnable() {
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() {
62
60
  @Override
63
61
  public void run() {
64
62
  for (Listener l : LISTENERS) l.onMotionSettingsChanged();
65
63
  }
66
- });
64
+ }, 250);
67
65
  }
68
66
  };
69
67
  Uri uri = Settings.Global.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-skeleton-native",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Skeleton and shimmer placeholders for React Native whose animation runs on the platform compositor (Core Animation on iOS, RenderThread on Android), so it keeps moving while the JS thread and the UI thread are busy. Old and New Architecture.",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",