react-native-tpstreams 0.1.3 → 0.1.4

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.
@@ -1,5 +1,6 @@
1
1
  package com.tpstreams
2
2
 
3
+ import kotlinx.coroutines.*
3
4
  import android.content.Context
4
5
  import android.util.AttributeSet
5
6
  import android.widget.FrameLayout
@@ -10,7 +11,7 @@ import com.facebook.react.uimanager.ThemedReactContext
10
11
  class TpStreamsPlayerView @JvmOverloads constructor(
11
12
  context: Context,
12
13
  attrs: AttributeSet? = null
13
- ) : FrameLayout(context, attrs) {
14
+ ) : FrameLayout(context, attrs), CoroutineScope {
14
15
 
15
16
  private var videoId: String? = null
16
17
  private var accessToken: String? = null
@@ -18,6 +19,10 @@ class TpStreamsPlayerView @JvmOverloads constructor(
18
19
  private var autoPlay :Boolean = true
19
20
  private var fragmentModule: FragmentModule? = null
20
21
 
22
+ private val job = SupervisorJob()
23
+ override val coroutineContext = Dispatchers.Main + job
24
+ private var updateJob: Job? = null
25
+
21
26
  init {
22
27
  if (context is ThemedReactContext) {
23
28
  val reactContext = context.reactApplicationContext
@@ -51,13 +56,23 @@ class TpStreamsPlayerView @JvmOverloads constructor(
51
56
 
52
57
  private fun updateFragment() {
53
58
  if (!videoId.isNullOrEmpty() && !accessToken.isNullOrEmpty()) {
54
- fragmentModule?.closeCustomFragment()
55
- fragmentModule?.showCustomFragment(videoId!!, accessToken!!, enableDownload, autoPlay)
59
+ updateJob?.cancel()
60
+ updateJob = launch {
61
+ delay(50)
62
+ fragmentModule?.closeCustomFragment()
63
+ fragmentModule?.showCustomFragment(
64
+ videoId!!,
65
+ accessToken!!,
66
+ enableDownload,
67
+ autoPlay ?: true
68
+ )
69
+ }
56
70
  }
57
71
  }
58
72
 
59
73
  override fun onDetachedFromWindow() {
60
74
  super.onDetachedFromWindow()
75
+ coroutineContext.cancel()
61
76
  fragmentModule?.closeCustomFragment()
62
77
  }
63
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Video Component for TPStreams",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",