rn-newarch-svga-player 1.1.6 → 1.1.16
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/README.md +49 -14
- package/android/build.gradle +25 -53
- package/android/gradle.properties +4 -5
- package/android/src/main/java/com/svgaplayer/RNSvgaPlayerManager.kt +35 -14
- package/ios/RCTSvgaPlayer.mm +31 -17
- package/package.json +1 -1
package/README.md
CHANGED
@@ -27,6 +27,55 @@ npm install rn-newarch-svga-player
|
|
27
27
|
|
28
28
|
```bash
|
29
29
|
yarn add rn-newarch-svga-player
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
> 若想更改库的别名 react-native-svga-player 来导入。你则需要把 rn-newarch-svga-player 库修改下,重新 yarn 执行
|
34
|
+
|
35
|
+
```diff
|
36
|
+
+ "dependencies": {
|
37
|
+
"@react-native-oh/react-native-harmony": "0.72.48",
|
38
|
+
"patch-package": "^8.0.0",
|
39
|
+
"postinstall-postinstall": "^2.1.0",
|
40
|
+
"react": "18.2.0",
|
41
|
+
"react-native": "0.72.5",
|
42
|
+
- "rn-newarch-svga-player":"^latest"
|
43
|
+
+ "react-native-svga-player":"npm:rn-newarch-svga-player@latest"
|
44
|
+
},
|
45
|
+
```
|
46
|
+
|
47
|
+
android 需要
|
48
|
+
|
49
|
+
```bash
|
50
|
+
./gradlew generateCodegenArtifactsFromSchema
|
51
|
+
```
|
52
|
+
|
53
|
+
ios 需要
|
54
|
+
|
55
|
+
```bash
|
56
|
+
cd ios
|
57
|
+
bundle install && bundle exec pod install
|
58
|
+
```
|
59
|
+
|
60
|
+
### ios react-native 0.76 以上 AppDelegate.mm 需要显示注册该组件
|
61
|
+
|
62
|
+
```diff
|
63
|
+
#import "AppDelegate.h"
|
64
|
+
#import "RCTSvgaPlayer.h"
|
65
|
+
#import <React/RCTBundleURLProvider.h>
|
66
|
+
#import <React/RCTBridge+Private.h>
|
67
|
+
|
68
|
+
@implementation AppDelegate
|
69
|
+
// ...
|
70
|
+
|
71
|
+
+ - (NSDictionary<NSString *,Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
|
72
|
+
+ {
|
73
|
+
+ NSMutableDictionary * dictionary = [super thirdPartyFabricComponents].mutableCopy;
|
74
|
+
+ dictionary[@"RNSvgaPlayer"] = [RCTSvgaPlayer class];
|
75
|
+
+ return dictionary;
|
76
|
+
+ }
|
77
|
+
|
78
|
+
@end
|
30
79
|
```
|
31
80
|
|
32
81
|
## API 参考
|
@@ -55,20 +104,6 @@ yarn add rn-newarch-svga-player
|
|
55
104
|
| `stepToFrame(frame, andPlay)` | 跳转到指定帧,可选择是否从该帧开始播放 |
|
56
105
|
| `stepToPercentage(percentage, andPlay)` | 跳转到指定百分比位置 (0.0-1.0),可选择是否播放 |
|
57
106
|
|
58
|
-
> 若想更改库的别名 react-native-svga-player 来导入。你则需要把 rn-newarch-svga-player 库修改下,重新 yarn 执行
|
59
|
-
|
60
|
-
```diff
|
61
|
-
+ "dependencies": {
|
62
|
-
"@react-native-oh/react-native-harmony": "0.72.48",
|
63
|
-
"patch-package": "^8.0.0",
|
64
|
-
"postinstall-postinstall": "^2.1.0",
|
65
|
-
"react": "18.2.0",
|
66
|
-
"react-native": "0.72.5",
|
67
|
-
- "rn-newarch-svga-player":"^1.1.6"
|
68
|
-
+ "react-native-svga-player":"npm:rn-newarch-svga-player@1.1.6"
|
69
|
-
},
|
70
|
-
```
|
71
|
-
|
72
107
|
下面的代码展示了这个库的基本使用场景:
|
73
108
|
|
74
109
|
```js
|
package/android/build.gradle
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
import java.nio.file.Paths
|
1
2
|
buildscript {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
ext.safeExtGet = {prop ->
|
4
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : project.properties['SvgaPlayer_' + prop]
|
5
|
+
}
|
6
6
|
repositories {
|
7
7
|
// 使用阿里云镜像源
|
8
8
|
maven { url 'https://maven.aliyun.com/repository/google' }
|
@@ -15,9 +15,10 @@ buildscript {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
dependencies {
|
18
|
-
classpath "com.android.tools.build:gradle:7.
|
18
|
+
classpath "com.android.tools.build:gradle:7.0.4"
|
19
19
|
// noinspection DifferentKotlinGradleVersion
|
20
|
-
classpath
|
20
|
+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion')}")
|
21
|
+
|
21
22
|
}
|
22
23
|
}
|
23
24
|
|
@@ -29,6 +30,17 @@ apply plugin: "com.facebook.react"
|
|
29
30
|
def getExtOrIntegerDefault(name) {
|
30
31
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["SvgaPlayer_" + name]).toInteger()
|
31
32
|
}
|
33
|
+
static def findNodeModulePath(baseDir, packageName) {
|
34
|
+
def basePath = baseDir.toPath().normalize()
|
35
|
+
while (basePath) {
|
36
|
+
def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
|
37
|
+
if (candidatePath.toFile().exists()) {
|
38
|
+
return candidatePath.toString()
|
39
|
+
}
|
40
|
+
basePath = basePath.getParent()
|
41
|
+
}
|
42
|
+
return null
|
43
|
+
}
|
32
44
|
|
33
45
|
android {
|
34
46
|
namespace "com.svgaplayer"
|
@@ -39,59 +51,19 @@ android {
|
|
39
51
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
40
52
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
41
53
|
}
|
42
|
-
|
43
|
-
buildFeatures {
|
44
|
-
buildConfig true
|
45
|
-
}
|
46
|
-
|
47
|
-
buildTypes {
|
48
|
-
release {
|
49
|
-
minifyEnabled false
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
lintOptions {
|
54
|
-
disable "GradleCompatible"
|
55
|
-
}
|
56
|
-
|
57
|
-
compileOptions {
|
58
|
-
sourceCompatibility JavaVersion.VERSION_1_8
|
59
|
-
targetCompatibility JavaVersion.VERSION_1_8
|
60
|
-
}
|
61
|
-
|
62
|
-
sourceSets {
|
63
|
-
main {
|
64
|
-
java.srcDirs += [
|
65
|
-
"generated/java",
|
66
|
-
"generated/jni"
|
67
|
-
]
|
68
|
-
}
|
69
|
-
}
|
70
54
|
}
|
55
|
+
def reactNativePath = findNodeModulePath(projectDir, "react-native")
|
71
56
|
|
72
57
|
repositories {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
// 添加 JitPack 仓库(用于 GitHub 依赖)
|
79
|
-
maven { url 'https://jitpack.io' }
|
80
|
-
// 备用官方源
|
81
|
-
mavenCentral()
|
82
|
-
google()
|
58
|
+
maven {
|
59
|
+
url "${reactNativePath}/android"
|
60
|
+
}
|
61
|
+
mavenCentral()
|
62
|
+
google()
|
83
63
|
}
|
84
64
|
|
85
|
-
def kotlin_version = getExtOrDefault("kotlinVersion")
|
86
|
-
|
87
65
|
dependencies {
|
88
66
|
implementation "com.facebook.react:react-android"
|
89
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$
|
67
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:${safeExtGet('kotlinVersion')}"
|
90
68
|
implementation "com.github.yyued:SVGAPlayer-Android:2.6.1"
|
91
69
|
}
|
92
|
-
|
93
|
-
react {
|
94
|
-
jsRootDir = file("../src/")
|
95
|
-
libraryName = "RNSvgaPlayer"
|
96
|
-
codegenJavaPackageName = "com.svgaplayer"
|
97
|
-
}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# SvgaPlayer_ndkVersion=27.1.12297006
|
1
|
+
SvgaPlayer_kotlinVersion=1.6.0
|
2
|
+
SvgaPlayer_minSdkVersion=21
|
3
|
+
SvgaPlayer_targetSdkVersion=31
|
4
|
+
SvgaPlayer_compileSdkVersion=31
|
@@ -4,7 +4,6 @@ import android.util.Log
|
|
4
4
|
import android.widget.ImageView
|
5
5
|
import com.facebook.react.bridge.Arguments
|
6
6
|
import com.facebook.react.bridge.ReadableArray
|
7
|
-
import com.facebook.react.common.MapBuilder
|
8
7
|
import com.facebook.react.module.annotations.ReactModule
|
9
8
|
import com.facebook.react.uimanager.SimpleViewManager
|
10
9
|
import com.facebook.react.uimanager.ThemedReactContext
|
@@ -158,29 +157,51 @@ class RNSvgaPlayerManager() : SimpleViewManager<RNSvgaPlayer>(), RNSvgaPlayerMan
|
|
158
157
|
view.stopAnimation(view.clearsAfterStop)
|
159
158
|
}
|
160
159
|
|
161
|
-
// override fun
|
160
|
+
// override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
|
162
161
|
// val export = super.getExportedCustomDirectEventTypeConstants()?.toMutableMap()
|
163
162
|
// ?: mutableMapOf<String, Any>()
|
164
|
-
//
|
165
163
|
// export[TopErrorEvent.EVENT_NAME] = mapOf("registrationName" to "onError")
|
166
164
|
// export[TopFinishedEvent.EVENT_NAME] = mapOf("registrationName" to "onFinished")
|
167
165
|
// export[TopLoadedEvent.EVENT_NAME] = mapOf("registrationName" to "onLoaded")
|
168
166
|
// export[TopFrameEvent.EVENT_NAME] = mapOf("registrationName" to "onFrameChanged")
|
169
167
|
// export[TopPercentageEvent.EVENT_NAME] = mapOf("registrationName" to "onPercentageChanged")
|
170
|
-
//
|
171
168
|
// return export
|
172
169
|
// }
|
173
|
-
|
174
|
-
val map
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
170
|
+
override fun getExportedCustomBubblingEventTypeConstants(): MutableMap<String, Any> {
|
171
|
+
val map: MutableMap<String, Any> = HashMap()
|
172
|
+
map["onError"] = createBubblingEventConfig(
|
173
|
+
bubbledName = "onError",
|
174
|
+
capturedName = "onErrorCapture"
|
175
|
+
)
|
176
|
+
map["onFinished"] = createBubblingEventConfig(
|
177
|
+
bubbledName = "onFinished",
|
178
|
+
capturedName = "onFinishedCapture"
|
179
|
+
)
|
180
|
+
map["onLoaded"] = createBubblingEventConfig(
|
181
|
+
bubbledName = "onLoaded",
|
182
|
+
capturedName = "onLoadedCapture"
|
183
|
+
)
|
184
|
+
map["onFrameChanged"] = createBubblingEventConfig(
|
185
|
+
bubbledName = "onFrameChanged",
|
186
|
+
capturedName = "onFrameChangedCapture"
|
187
|
+
)
|
188
|
+
map["onPercentageChanged"] = createBubblingEventConfig(
|
189
|
+
bubbledName = "onPercentageChanged",
|
190
|
+
capturedName = "onPercentageChangedCapture"
|
191
|
+
)
|
192
|
+
return map;
|
193
|
+
}
|
194
|
+
private fun createBubblingEventConfig(
|
195
|
+
bubbledName: String,
|
196
|
+
capturedName: String
|
197
|
+
): Map<String, Any> {
|
198
|
+
return mapOf(
|
199
|
+
"phasedRegistrationNames" to mapOf(
|
200
|
+
"bubbled" to bubbledName,
|
201
|
+
"captured" to capturedName
|
202
|
+
)
|
203
|
+
)
|
182
204
|
}
|
183
|
-
|
184
205
|
override fun pauseAnimation(view: RNSvgaPlayer?) {
|
185
206
|
view?.pauseAnimation()
|
186
207
|
}
|
package/ios/RCTSvgaPlayer.mm
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#import "RCTSvgaPlayer.h"
|
2
|
-
|
3
2
|
#import <react/renderer/components/RNSvgaPlayerSpec/ComponentDescriptors.h>
|
4
3
|
#import <react/renderer/components/RNSvgaPlayerSpec/EventEmitters.h>
|
5
4
|
#import <react/renderer/components/RNSvgaPlayerSpec/Props.h>
|
@@ -16,6 +15,7 @@ using namespace facebook::react;
|
|
16
15
|
|
17
16
|
@end
|
18
17
|
|
18
|
+
|
19
19
|
@implementation RCTSvgaPlayer {
|
20
20
|
SVGAPlayer * _svgaPlayer;
|
21
21
|
NSString * _currentSource;
|
@@ -35,11 +35,9 @@ using namespace facebook::react;
|
|
35
35
|
{
|
36
36
|
return concreteComponentDescriptorProvider<RNSvgaPlayerComponentDescriptor>();
|
37
37
|
}
|
38
|
-
|
39
|
-
|
40
38
|
Class<RCTComponentViewProtocol> RNSvgaPlayerCls(void)
|
41
39
|
{
|
42
|
-
|
40
|
+
return RCTSvgaPlayer.class;
|
43
41
|
}
|
44
42
|
- (instancetype)initWithFrame:(CGRect)frame
|
45
43
|
{
|
@@ -141,8 +139,10 @@ Class<RCTComponentViewProtocol> RNSvgaPlayerCls(void)
|
|
141
139
|
[_svgaPlayer clear];
|
142
140
|
_currentVideoItem = nil;
|
143
141
|
|
144
|
-
|
145
|
-
|
142
|
+
if(_eventEmitter!= nullptr) {
|
143
|
+
RNSvgaPlayerEventEmitter::OnError result = RNSvgaPlayerEventEmitter::OnError{RNSvgaPlayerEventEmitter::OnError( [errorMessage UTF8String] )};
|
144
|
+
self.eventEmitter.onError(result);
|
145
|
+
}
|
146
146
|
|
147
147
|
// if (_eventEmitter != nullptr) {
|
148
148
|
// std::dynamic_pointer_cast<const facebook::react::RNSvgaPlayerEventEmitter>(_eventEmitter)
|
@@ -157,10 +157,12 @@ self.eventEmitter.onError(result);
|
|
157
157
|
// if (_eventEmitter != nullptr) {
|
158
158
|
// std::dynamic_pointer_cast<const facebook::react::RNSvgaPlayerEventEmitter>(_eventEmitter)
|
159
159
|
// ->onLoaded(facebook::react::RNSvgaPlayerEventEmitter::OnLoaded{});
|
160
|
-
//
|
160
|
+
//
|
161
161
|
// }
|
162
|
-
|
163
|
-
|
162
|
+
if(_eventEmitter != nullptr) {
|
163
|
+
RNSvgaPlayerEventEmitter::OnLoaded result = RNSvgaPlayerEventEmitter::OnLoaded{RNSvgaPlayerEventEmitter::OnLoaded( {} )};
|
164
|
+
self.eventEmitter.onLoaded(result);
|
165
|
+
}
|
164
166
|
}
|
165
167
|
|
166
168
|
// 辅助方法:处理文件路径
|
@@ -438,10 +440,14 @@ self.eventEmitter.onLoaded(result);
|
|
438
440
|
if (!_svgaPlayer || _svgaPlayer.delegate != self) {
|
439
441
|
return;
|
440
442
|
}
|
441
|
-
|
442
|
-
|
443
|
+
if(_eventEmitter!= nullptr) {
|
444
|
+
|
445
|
+
RNSvgaPlayerEventEmitter::OnFrameChanged result = RNSvgaPlayerEventEmitter::OnFrameChanged{RNSvgaPlayerEventEmitter::OnFrameChanged( frame )};
|
446
|
+
self.eventEmitter.onFrameChanged(result);
|
447
|
+
}
|
443
448
|
// std::dynamic_pointer_cast<const RNSvgaPlayerEventEmitter>(_eventEmitter)
|
444
449
|
// ->onFrameChanged(RNSvgaPlayerEventEmitter::OnFrameChanged{.value=(float)frame});
|
450
|
+
|
445
451
|
|
446
452
|
}
|
447
453
|
-(void) svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage{
|
@@ -449,9 +455,11 @@ self.eventEmitter.onFrameChanged(result);
|
|
449
455
|
if (!_svgaPlayer || _svgaPlayer.delegate != self) {
|
450
456
|
return;
|
451
457
|
}
|
452
|
-
|
453
|
-
|
454
|
-
|
458
|
+
if(_eventEmitter != nullptr) {
|
459
|
+
|
460
|
+
RNSvgaPlayerEventEmitter::OnPercentageChanged result = RNSvgaPlayerEventEmitter::OnPercentageChanged{RNSvgaPlayerEventEmitter::OnPercentageChanged( percentage )};
|
461
|
+
self.eventEmitter.onPercentageChanged(result);
|
462
|
+
}
|
455
463
|
//直接事件
|
456
464
|
// std::dynamic_pointer_cast<const RNSvgaPlayerEventEmitter>(_eventEmitter)
|
457
465
|
// ->onFrameChanged(RNSvgaPlayerEventEmitter::OnFrameChanged{.value=(float)percentage});
|
@@ -464,9 +472,12 @@ self.eventEmitter.onFrameChanged(result);
|
|
464
472
|
if (!_svgaPlayer || player != _svgaPlayer) {
|
465
473
|
return;
|
466
474
|
}
|
467
|
-
|
468
|
-
|
469
|
-
|
475
|
+
if(_eventEmitter != nullptr) {
|
476
|
+
|
477
|
+
// 检查事件发送器是否还有效
|
478
|
+
RNSvgaPlayerEventEmitter::OnFinished result = RNSvgaPlayerEventEmitter::OnFinished{RNSvgaPlayerEventEmitter::OnFinished( true )};
|
479
|
+
self.eventEmitter.onFinished(result);
|
480
|
+
}
|
470
481
|
// std::dynamic_pointer_cast<const facebook::react::RNSvgaPlayerEventEmitter>(_eventEmitter)
|
471
482
|
// ->onFinished(facebook::react::RNSvgaPlayerEventEmitter::OnFinished{
|
472
483
|
// .finished = true
|
@@ -552,5 +563,8 @@ self.eventEmitter.onFinished(result);
|
|
552
563
|
_currentSource = nil;
|
553
564
|
}
|
554
565
|
|
566
|
+
|
567
|
+
|
555
568
|
@end
|
556
569
|
|
570
|
+
|
package/package.json
CHANGED
@@ -53,5 +53,5 @@
|
|
53
53
|
"scripts": {
|
54
54
|
"codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-ohos-svgaplayer --cpp-output-path ../../harmony/svgaplayer/src/main/cpp/generated --ets-output-path ../../harmony/svgaplayer/src/main/ets/generated --turbo-modules-spec-paths ./src --arkts-components-spec-paths ./src"
|
55
55
|
},
|
56
|
-
"version": "1.1.
|
56
|
+
"version": "1.1.16"
|
57
57
|
}
|