1
1
package com.opensource.svgaplayer_react
2
2
3
3
import android.content.Context
4
- import android.support.annotation.NonNull
5
4
import com.facebook.react.uimanager.SimpleViewManager
6
5
import com.facebook.react.uimanager.ThemedReactContext
7
6
import com.facebook.react.uimanager.annotations.ReactProp
8
- import com.opensource.svgaplayer.SVGAImageView
9
7
import com.opensource.svgaplayer.SVGAParser
10
8
import com.opensource.svgaplayer.SVGAVideoEntity
11
9
import java.net.URL
12
10
13
11
/* *
14
12
* Created by cuiminghui on 2017/6/16.
15
13
*/
16
- class RCTSVGAPlayerManager : SimpleViewManager <SVGAImageView >() {
14
+ class RCTSVGAPlayerManager : SimpleViewManager <RCTSVGAImageView >() {
17
15
18
16
override fun getName (): String {
19
17
return " SVGAPlayer"
20
18
}
21
19
22
- override fun createViewInstance (reactContext : ThemedReactContext ? ): SVGAImageView {
23
- return SVGAImageView (reactContext as Context )
20
+ override fun createViewInstance (reactContext : ThemedReactContext ? ): RCTSVGAImageView {
21
+ return RCTSVGAImageView (reactContext as Context )
24
22
}
25
23
26
24
@ReactProp(name = " source" )
27
- fun setSource (view : SVGAImageView , source : String ) {
25
+ fun setSource (view : RCTSVGAImageView , source : String ) {
28
26
if (source.startsWith(" http" ) || source.startsWith(" https" )) {
29
27
try {
30
28
SVGAParser (view.context).parse(URL (source), object : SVGAParser .ParseCompletion {
@@ -36,6 +34,65 @@ class RCTSVGAPlayerManager: SimpleViewManager<SVGAImageView>() {
36
34
})
37
35
} catch (e: Exception ) {}
38
36
}
37
+ else {
38
+ try {
39
+ SVGAParser (view.context).parse(source, object : SVGAParser .ParseCompletion {
40
+ override fun onComplete (videoItem : SVGAVideoEntity ) {
41
+ view.setVideoItem(videoItem)
42
+ view.startAnimation()
43
+ }
44
+ override fun onError () { }
45
+ })
46
+ } catch (e: Exception ) {}
47
+ }
48
+ }
49
+
50
+ @ReactProp(name = " loops" , defaultInt = 0 )
51
+ fun setLoops (view : RCTSVGAImageView , loops : Int ) {
52
+ view.loops = loops
53
+ }
54
+
55
+ @ReactProp(name = " clearsAfterStop" , defaultBoolean = true )
56
+ fun setClearsAfterStop (view : RCTSVGAImageView , clearsAfterStop : Boolean ) {
57
+ view.clearsAfterStop = clearsAfterStop
58
+ }
59
+
60
+ @ReactProp(name = " currentState" )
61
+ fun setCurrentState (view : RCTSVGAImageView , currentState : String ) {
62
+ view.currentState = currentState
63
+ when (currentState) {
64
+ " start" -> {
65
+ view.startAnimation()
66
+ }
67
+ " pause" -> {
68
+ view.pauseAnimation()
69
+ }
70
+ " stop" -> {
71
+ view.stopAnimation()
72
+ }
73
+ " clear" -> {
74
+ view.stopAnimation(true )
75
+ }
76
+ else -> {
77
+
78
+ }
79
+ }
80
+ }
81
+
82
+ @ReactProp(name = " toFrame" , defaultInt = - 1 )
83
+ fun setToFrame (view : RCTSVGAImageView , toFrame : Int ) {
84
+ if (toFrame < 0 ) {
85
+ return
86
+ }
87
+ view.stepToFrame(toFrame, view.currentState?.equals(" play" ) ? : false )
88
+ }
89
+
90
+ @ReactProp(name = " toPercentage" , defaultFloat = - 1.0f )
91
+ fun setToPercentage (view : RCTSVGAImageView , toPercentage : Float ) {
92
+ if (toPercentage < 0 ) {
93
+ return
94
+ }
95
+ view.stepToPercentage(toPercentage.toDouble(), view.currentState?.equals(" play" ) ? : false )
39
96
}
40
97
41
98
}
0 commit comments