react-native-spalla-player 0.16.1 → 0.16.3

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.
@@ -11,6 +11,7 @@ class SpallaPlayerPipModule(reactContext: ReactApplicationContext) : ReactContex
11
11
  companion object {
12
12
  const val NAME = "SpallaPlayerPipModule"
13
13
  private var activePlayerManager: RNSpallaPlayerManager? = null
14
+ private var instance: SpallaPlayerPipModule? = null
14
15
 
15
16
  fun registerPlayerManager(manager: RNSpallaPlayerManager) {
16
17
  activePlayerManager = manager
@@ -21,12 +22,27 @@ class SpallaPlayerPipModule(reactContext: ReactApplicationContext) : ReactContex
21
22
  activePlayerManager = null
22
23
  }
23
24
  }
25
+
26
+ /**
27
+ * A static method that MainActivity can call without needing a ReactContext.
28
+ * It safely forwards the call to the active module instance.
29
+ */
30
+ fun triggerUserLeaveHint() {
31
+ // Check if an instance exists before calling the method
32
+ instance?.onUserLeaveHint()
33
+ }
24
34
  }
25
35
 
26
36
  override fun getName(): String = NAME
27
37
 
38
+ init {
39
+ // When React Native creates the module, assign it to our static property
40
+ instance = this
41
+ }
42
+
28
43
  @ReactMethod
29
44
  fun onUserLeaveHint() {
30
45
  activePlayerManager?.triggerPipImmediate()
31
46
  }
47
+
32
48
  }
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/withPipAndroid');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spalla-player",
3
- "version": "0.16.1",
3
+ "version": "0.16.3",
4
4
  "description": "Spalla SDK for RN",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -15,7 +15,8 @@
15
15
  "types": "./lib/typescript/commonjs/src/index.d.ts",
16
16
  "default": "./lib/commonjs/index.js"
17
17
  }
18
- }
18
+ },
19
+ "./app.plugin.js": "./app.plugin.js"
19
20
  },
20
21
  "files": [
21
22
  "src",
@@ -23,6 +24,8 @@
23
24
  "android",
24
25
  "ios",
25
26
  "cpp",
27
+ "plugin",
28
+ "app.plugin.js",
26
29
  "*.podspec",
27
30
  "!ios/build",
28
31
  "!android/build",
@@ -183,5 +186,11 @@
183
186
  "type": "view-legacy",
184
187
  "languages": "kotlin-swift",
185
188
  "version": "0.41.2"
189
+ },
190
+ "expo": {
191
+ "plugin": "./app.plugin.js"
192
+ },
193
+ "dependencies": {
194
+ "@expo/config-plugins": "^54.0.4"
186
195
  }
187
196
  }
@@ -0,0 +1,2 @@
1
+ module.exports = require('./withPipAndroid');
2
+ module.exports.default = module.exports;
@@ -0,0 +1,68 @@
1
+ const {
2
+ withAndroidManifest,
3
+ withMainActivity,
4
+ } = require('@expo/config-plugins');
5
+
6
+ /**
7
+ * Adds supportsPictureInPicture="true" to MainActivity
8
+ */
9
+ function withPipManifest(config) {
10
+ return withAndroidManifest(config, (config) => {
11
+ const manifest = config.modResults.manifest;
12
+ const app = manifest.application?.[0];
13
+
14
+ if (!app?.activity) return config;
15
+
16
+ const mainActivity = app.activity.find(
17
+ (activity) => activity.$?.['android:name'] === '.MainActivity'
18
+ );
19
+
20
+ if (!mainActivity) return config;
21
+
22
+ mainActivity.$['android:supportsPictureInPicture'] = 'true';
23
+ return config;
24
+ });
25
+ }
26
+
27
+ /**
28
+ * Injects onUserLeaveHint() into MainActivity.kt
29
+ */
30
+ function withPipMainActivity(config) {
31
+ return withMainActivity(config, (config) => {
32
+ let contents = config.modResults.contents;
33
+
34
+ if (contents.includes('override fun onUserLeaveHint()')) {
35
+ return config;
36
+ }
37
+
38
+ // Add necessary imports
39
+ if (!contents.includes('import com.spallaplayer.SpallaPlayerPipModule')) {
40
+ contents = contents.replace(
41
+ /import\s+android\.os\.Bundle/,
42
+ `import android.os.Bundle
43
+ import com.spallaplayer.SpallaPlayerPipModule`
44
+ );
45
+ }
46
+
47
+ const method = `
48
+ override fun onUserLeaveHint() {
49
+ super.onUserLeaveHint()
50
+ SpallaPlayerPipModule.triggerUserLeaveHint()
51
+ }
52
+ `;
53
+
54
+ contents = contents.replace(
55
+ /class MainActivity[^{]*\{/,
56
+ (match) => `${match}${method}`
57
+ );
58
+
59
+ config.modResults.contents = contents;
60
+ return config;
61
+ });
62
+ }
63
+
64
+ module.exports = function withPipAndroid(config) {
65
+ config = withPipManifest(config);
66
+ config = withPipMainActivity(config);
67
+ return config;
68
+ };