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,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,81 @@
|
|
|
1
|
+
package com.skeletonnative;
|
|
2
|
+
|
|
3
|
+
import android.animation.ValueAnimator;
|
|
4
|
+
import android.content.ContentResolver;
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.database.ContentObserver;
|
|
7
|
+
import android.net.Uri;
|
|
8
|
+
import android.os.Build;
|
|
9
|
+
import android.os.Handler;
|
|
10
|
+
import android.os.Looper;
|
|
11
|
+
import android.provider.Settings;
|
|
12
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Process-wide view of the system animation settings. Android has no separate
|
|
16
|
+
* "reduce motion" flag for apps: the accessibility setting "Remove animations"
|
|
17
|
+
* and the developer option both set {@code ANIMATOR_DURATION_SCALE} to 0, which
|
|
18
|
+
* disables every animator, including AnimatedVectorDrawable. A ContentObserver
|
|
19
|
+
* on that setting tells attached views when it changes.
|
|
20
|
+
*/
|
|
21
|
+
final class SkeletonMotion {
|
|
22
|
+
interface Listener {
|
|
23
|
+
void onMotionSettingsChanged();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private static final CopyOnWriteArrayList<Listener> LISTENERS = new CopyOnWriteArrayList<>();
|
|
27
|
+
private static ContentObserver observer;
|
|
28
|
+
|
|
29
|
+
private SkeletonMotion() {}
|
|
30
|
+
|
|
31
|
+
static float durationScale(Context context) {
|
|
32
|
+
if (Build.VERSION.SDK_INT >= 26) {
|
|
33
|
+
return ValueAnimator.getDurationScale();
|
|
34
|
+
}
|
|
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
|
+
if (Build.VERSION.SDK_INT >= 26) {
|
|
48
|
+
return ValueAnimator.areAnimatorsEnabled();
|
|
49
|
+
}
|
|
50
|
+
return settingsScale(context) != 0f;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static void addListener(Context context, Listener listener) {
|
|
54
|
+
LISTENERS.addIfAbsent(listener);
|
|
55
|
+
if (observer == null) {
|
|
56
|
+
final ContentResolver resolver = context.getApplicationContext().getContentResolver();
|
|
57
|
+
observer = new ContentObserver(new Handler(Looper.getMainLooper())) {
|
|
58
|
+
@Override
|
|
59
|
+
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() {
|
|
62
|
+
@Override
|
|
63
|
+
public void run() {
|
|
64
|
+
for (Listener l : LISTENERS) l.onMotionSettingsChanged();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
Uri uri = Settings.Global.getUriFor(Settings.Global.ANIMATOR_DURATION_SCALE);
|
|
70
|
+
try {
|
|
71
|
+
resolver.registerContentObserver(uri, false, observer);
|
|
72
|
+
} catch (RuntimeException e) {
|
|
73
|
+
observer = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static void removeListener(Listener listener) {
|
|
79
|
+
LISTENERS.remove(listener);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -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
|
+
}
|