Skip to content

Commit 0c3e236

Browse files
committed
use activity as context.
1 parent be255f9 commit 0c3e236

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

react/src/main/java/com/opensource/svgaplayer_react/RCTSVGAPlayerManager.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.opensource.svgaplayer_react
22

33
import android.content.Context
4+
import com.facebook.react.bridge.ReactContext
45
import com.facebook.react.uimanager.SimpleViewManager
56
import com.facebook.react.uimanager.ThemedReactContext
67
import com.facebook.react.uimanager.annotations.ReactProp
@@ -23,9 +24,10 @@ class RCTSVGAPlayerManager: SimpleViewManager<RCTSVGAImageView>() {
2324

2425
@ReactProp(name = "source")
2526
fun setSource(view: RCTSVGAImageView, source: String) {
27+
val context = (view.context as? ReactContext)?.currentActivity ?: return
2628
if (source.startsWith("http") || source.startsWith("https")) {
2729
try {
28-
SVGAParser(view.context).parse(URL(source), object: SVGAParser.ParseCompletion {
30+
SVGAParser(context).parse(URL(source), object: SVGAParser.ParseCompletion {
2931
override fun onComplete(videoItem: SVGAVideoEntity) {
3032
view.setVideoItem(videoItem)
3133
view.startAnimation()
@@ -36,7 +38,7 @@ class RCTSVGAPlayerManager: SimpleViewManager<RCTSVGAImageView>() {
3638
}
3739
else {
3840
try {
39-
SVGAParser(view.context).parse(source, object: SVGAParser.ParseCompletion {
41+
SVGAParser(context).parse(source, object: SVGAParser.ParseCompletion {
4042
override fun onComplete(videoItem: SVGAVideoEntity) {
4143
view.setVideoItem(videoItem)
4244
view.startAnimation()

0 commit comments

Comments
 (0)