react-native-spalla-player 0.14.0 → 0.15.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.
@@ -14,186 +14,237 @@ import com.spalla.sdk.android.core.player.view.SpallaPlayerView
14
14
 
15
15
 
16
16
  class SpallaPlayerModule(reactContext: ReactApplicationContext) :
17
- ReactContextBaseJavaModule(reactContext),
18
- LifecycleEventListener {
19
- private val _reactContext: ReactApplicationContext
20
-
21
- init {
22
- reactContext.addLifecycleEventListener(this)
23
- _reactContext = reactContext
24
- }
25
-
26
- override fun getName(): String {
27
- return "RNSpallaPlayer"
28
- }
29
-
30
- override fun onHostResume() {
31
- }
32
-
33
- override fun onHostPause() {
34
-
35
- }
36
-
37
- override fun onHostDestroy() {
38
- }
39
-
40
- @ReactMethod
41
- fun play(tag: Int) {
42
- if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
43
- val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
44
- if (uiManager is UIManager) {
45
- uiManager.resolveView(tag)?.let { view ->
46
- if (view is SpallaPlayerContainerView) {
47
- view.post {
48
- view.spallaPlayerView.play()
49
- }
50
- } else {
51
- throw ClassCastException(
52
- "Cannot play: view with tag #$tag is not a SpallaPlayerView"
53
- )
54
- }
55
- }
17
+ ReactContextBaseJavaModule(reactContext),
18
+ LifecycleEventListener {
19
+ private val _reactContext: ReactApplicationContext
20
+
21
+ init {
22
+ reactContext.addLifecycleEventListener(this)
23
+ _reactContext = reactContext
24
+ }
25
+
26
+ override fun getName(): String {
27
+ return "RNSpallaPlayer"
28
+ }
29
+
30
+ override fun onHostResume() {
31
+ }
32
+
33
+ override fun onHostPause() {
34
+
35
+ }
36
+
37
+ override fun onHostDestroy() {
38
+ }
39
+
40
+ @ReactMethod
41
+ fun play(tag: Int) {
42
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
43
+ val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
44
+ if (uiManager is UIManager) {
45
+ uiManager.resolveView(tag)?.let { view ->
46
+ if (view is SpallaPlayerContainerView) {
47
+ view.post {
48
+ view.spallaPlayerView.play()
56
49
  }
50
+ } else {
51
+ throw ClassCastException(
52
+ "Cannot play: view with tag #$tag is not a SpallaPlayerView"
53
+ )
54
+ }
55
+ }
56
+ }
57
+ } else {
58
+ val uiManager: UIManagerModule? =
59
+ _reactContext.getNativeModule(UIManagerModule::class.java)
60
+ uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
61
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
62
+ if (playerView is SpallaPlayerContainerView) {
63
+ playerView.spallaPlayerView.play()
57
64
  } else {
58
- val uiManager: UIManagerModule? =
59
- _reactContext.getNativeModule(UIManagerModule::class.java)
60
- uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
61
- val playerView = nativeViewHierarchyManager.resolveView(tag)
62
- if (playerView is SpallaPlayerContainerView) {
63
- playerView.spallaPlayerView.play()
64
- } else {
65
- throw ClassCastException(
66
- String.format(
67
- "Cannot play: view with tag #%d is not a SpallaPlayerView",
68
- tag
69
- )
70
- )
71
- }
72
- }
65
+ throw ClassCastException(
66
+ String.format(
67
+ "Cannot play: view with tag #%d is not a SpallaPlayerView",
68
+ tag
69
+ )
70
+ )
73
71
  }
72
+ }
74
73
  }
75
-
76
- @ReactMethod
77
- fun pause(tag: Int) {
78
- if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
79
- val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
80
- if (uiManager is UIManager) {
81
- uiManager.resolveView(tag)?.let { view ->
82
- if (view is SpallaPlayerContainerView) {
83
- view.post {
84
- view.spallaPlayerView.pause()
85
- }
86
- } else {
87
- throw ClassCastException(
88
- "Cannot pause: view with tag #$tag is not a SpallaPlayerView"
89
- )
90
- }
91
- }
74
+ }
75
+
76
+ @ReactMethod
77
+ fun pause(tag: Int) {
78
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
79
+ val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
80
+ if (uiManager is UIManager) {
81
+ uiManager.resolveView(tag)?.let { view ->
82
+ if (view is SpallaPlayerContainerView) {
83
+ view.post {
84
+ view.spallaPlayerView.pause()
92
85
  }
86
+ } else {
87
+ throw ClassCastException(
88
+ "Cannot pause: view with tag #$tag is not a SpallaPlayerView"
89
+ )
90
+ }
91
+ }
92
+ }
93
+ } else {
94
+ val uiManager: UIManagerModule? =
95
+ _reactContext.getNativeModule(UIManagerModule::class.java)
96
+ uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
97
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
98
+ if (playerView is SpallaPlayerContainerView) {
99
+ playerView.spallaPlayerView.pause()
93
100
  } else {
94
- val uiManager: UIManagerModule? =
95
- _reactContext.getNativeModule(UIManagerModule::class.java)
96
- uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
97
- val playerView = nativeViewHierarchyManager.resolveView(tag)
98
- if (playerView is SpallaPlayerContainerView) {
99
- playerView.spallaPlayerView.pause()
100
- } else {
101
- throw ClassCastException(
102
- String.format(
103
- "Cannot play: view with tag #%d is not a SpallaPplayerView",
104
- tag
105
- )
106
- )
107
- }
108
- }
101
+ throw ClassCastException(
102
+ String.format(
103
+ "Cannot play: view with tag #%d is not a SpallaPplayerView",
104
+ tag
105
+ )
106
+ )
109
107
  }
110
-
111
-
108
+ }
112
109
  }
113
-
114
- @ReactMethod
115
- fun seekTo(tag: Int, time: Double) {
116
- _reactContext.getNativeModule(UIManagerModule::class.java)!!
117
- .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
118
- val playerView = nativeViewHierarchyManager.resolveView(tag)
119
- if (playerView is SpallaPlayerContainerView) {
120
- playerView.spallaPlayerView.seekTo(time)
121
- } else {
122
- throw ClassCastException(
123
- String.format(
124
- "Cannot play: view with tag #%d is not a SpallaPplayerView",
125
- tag
126
- )
127
- )
128
- }
110
+ }
111
+
112
+ @ReactMethod
113
+ fun seekTo(tag: Int, time: Double) {
114
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
115
+ val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
116
+ if (uiManager is UIManager) {
117
+ uiManager.resolveView(tag)?.let { view ->
118
+ if (view is SpallaPlayerContainerView) {
119
+ view.post {
120
+ view.spallaPlayerView.seekTo(time)
129
121
  }
122
+ } else {
123
+ throw ClassCastException(
124
+ "Cannot play: view with tag #$tag is not a SpallaPlayerView"
125
+ )
126
+ }
127
+ }
128
+ }
129
+ } else {
130
+ _reactContext.getNativeModule(UIManagerModule::class.java)!!
131
+ .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
132
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
133
+ if (playerView is SpallaPlayerContainerView) {
134
+ playerView.spallaPlayerView.seekTo(time)
135
+ } else {
136
+ throw ClassCastException(
137
+ String.format(
138
+ "Cannot play: view with tag #%d is not a SpallaPplayerView",
139
+ tag
140
+ )
141
+ )
142
+ }
143
+ }
130
144
  }
131
-
132
- @ReactMethod
133
- fun selectSubtitle(tag: Int, subtitle: String?) {
134
- _reactContext.getNativeModule(UIManagerModule::class.java)!!
135
- .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
136
- val playerView = nativeViewHierarchyManager.resolveView(tag)
137
- if (playerView is SpallaPlayerContainerView) {
138
- playerView.spallaPlayerView.selectSubtitle(subtitle)
139
- } else {
140
- throw ClassCastException(
141
- String.format(
142
- "Cannot play: view with tag #%d is not a SpallaPplayerView",
143
- tag
144
- )
145
- )
146
- }
145
+ }
146
+
147
+ @ReactMethod
148
+ fun selectSubtitle(tag: Int, subtitle: String?) {
149
+
150
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
151
+ val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
152
+ if (uiManager is UIManager) {
153
+ uiManager.resolveView(tag)?.let { view ->
154
+ if (view is SpallaPlayerContainerView) {
155
+ view.post {
156
+ view.spallaPlayerView.selectSubtitle(subtitle)
147
157
  }
158
+ } else {
159
+ throw ClassCastException(
160
+ "Cannot play: view with tag #$tag is not a SpallaPlayerView"
161
+ )
162
+ }
163
+ }
164
+ }
165
+ } else {
166
+
167
+ _reactContext.getNativeModule(UIManagerModule::class.java)!!
168
+ .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
169
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
170
+ if (playerView is SpallaPlayerContainerView) {
171
+ playerView.spallaPlayerView.selectSubtitle(subtitle)
172
+ } else {
173
+ throw ClassCastException(
174
+ String.format(
175
+ "Cannot play: view with tag #%d is not a SpallaPplayerView",
176
+ tag
177
+ )
178
+ )
179
+ }
180
+ }
148
181
  }
149
-
150
- @ReactMethod
151
- fun selectPlaybackRate(tag: Int, rate: Double) {
152
- _reactContext.getNativeModule(UIManagerModule::class.java)!!
153
- .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
154
- val playerView = nativeViewHierarchyManager.resolveView(tag)
155
- if (playerView is SpallaPlayerContainerView) {
156
- playerView.spallaPlayerView.selectPlaybackRate(rate)
157
- } else {
158
- throw ClassCastException(
159
- String.format(
160
- "Cannot play: view with tag #%d is not a SpallaPplayerView",
161
- tag
162
- )
163
- )
164
- }
182
+ }
183
+
184
+ @ReactMethod
185
+ fun selectPlaybackRate(tag: Int, rate: Double) {
186
+
187
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
188
+ val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
189
+ if (uiManager is UIManager) {
190
+ uiManager.resolveView(tag)?.let { view ->
191
+ if (view is SpallaPlayerContainerView) {
192
+ view.post {
193
+ view.spallaPlayerView.play()
165
194
  }
195
+ } else {
196
+ throw ClassCastException(
197
+ "Cannot play: view with tag #$tag is not a SpallaPlayerView"
198
+ )
199
+ }
200
+ }
201
+ }
202
+ } else {
203
+ _reactContext.getNativeModule(UIManagerModule::class.java)!!
204
+ .prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
205
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
206
+ if (playerView is SpallaPlayerContainerView) {
207
+ playerView.spallaPlayerView.selectPlaybackRate(rate)
208
+ } else {
209
+ throw ClassCastException(
210
+ String.format(
211
+ "Cannot play: view with tag #%d is not a SpallaPplayerView",
212
+ tag
213
+ )
214
+ )
215
+ }
216
+ }
166
217
  }
167
-
168
- @ReactMethod
169
- fun unmount(tag: Int) {
170
- if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
171
- val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
172
- if (uiManager is UIManager) {
173
- uiManager.resolveView(tag)?.let { view ->
174
- if (view is SpallaPlayerContainerView) {
175
- view.post {
176
- view.spallaPlayerView.pause()
177
- }
178
- }
179
- }
180
- }
181
- } else {
182
- val uiManager: UIManagerModule? =
183
- _reactContext.getNativeModule(UIManagerModule::class.java)
184
- uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
185
- val playerView = nativeViewHierarchyManager.resolveView(tag)
186
- if (playerView is SpallaPlayerContainerView) {
187
- playerView.spallaPlayerView.pause()
188
- }
218
+ }
219
+
220
+ @ReactMethod
221
+ fun unmount(tag: Int) {
222
+ if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
223
+ val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
224
+ if (uiManager is UIManager) {
225
+ uiManager.resolveView(tag)?.let { view ->
226
+ if (view is SpallaPlayerContainerView) {
227
+ view.post {
228
+ view.spallaPlayerView.pause()
189
229
  }
230
+ }
190
231
  }
232
+ }
233
+ } else {
234
+ val uiManager: UIManagerModule? =
235
+ _reactContext.getNativeModule(UIManagerModule::class.java)
236
+ uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
237
+ val playerView = nativeViewHierarchyManager.resolveView(tag)
238
+ if (playerView is SpallaPlayerContainerView) {
239
+ playerView.spallaPlayerView.pause()
240
+ }
241
+ }
191
242
  }
243
+ }
192
244
 
193
- @ReactMethod
194
- fun initialize(token: String, applicationId: String?) {
195
- SpallaSDK.initialize(_reactContext, token)
196
- }
197
-
245
+ @ReactMethod
246
+ fun initialize(token: String, applicationId: String?) {
247
+ SpallaSDK.initialize(_reactContext, token)
248
+ }
198
249
 
199
250
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spalla-player",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Spalla SDK for RN",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
 
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
18
 
19
- s.dependency "SpallaSDK", "~> 2.2.4"
19
+ s.dependency "SpallaSDK", "~> 2.3.0"
20
20
 
21
21
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
22
22
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.