react-native-tpstreams 0.1.1 → 0.1.2

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.
@@ -65,24 +65,29 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
65
65
 
66
66
  @ReactMethod
67
67
  fun closeCustomFragment() {
68
- Log.e("FragmentModule", "closeCustomFragment() called")
69
- // Ensure the currentActivity is a FragmentActivity
70
- val activity = currentActivity as? FragmentActivity
71
- activity?.let {
72
- // Access the fragment manager
73
- val fragmentManager = it.supportFragmentManager
74
-
75
- // Check if there are any fragments in the back stack
76
- if (fragmentManager.backStackEntryCount > 0) {
77
- // Pop the last fragment off the back stack
78
- fragmentManager.popBackStack()
68
+ Log.e("FragmentModule", "closeCustomFragment() called")
69
+
70
+ // Ensure currentActivity is a FragmentActivity
71
+ val activity = currentActivity as? FragmentActivity
72
+ if (activity == null || activity.isFinishing || activity.isDestroyed) {
73
+ Log.e("FragmentModule", "Activity is null, finishing, or destroyed")
74
+ return
75
+ }
76
+
77
+ val fragmentManager = activity.supportFragmentManager
78
+ val playerFragment = fragmentManager.findFragmentByTag("PLAYER_FRAGMENT") as? PlayerFragment
79
+
80
+ if (playerFragment != null) {
81
+ Log.d("FragmentModule", "Removing PlayerFragment")
82
+ fragmentManager.beginTransaction()
83
+ .remove(playerFragment)
84
+ .commitAllowingStateLoss() // Avoid IllegalStateException
85
+ } else if (fragmentManager.backStackEntryCount > 0) {
86
+ Log.d("FragmentModule", "Popping back stack")
87
+ fragmentManager.popBackStack()
79
88
  } else {
80
- Log.e("FragmentModule", "No fragments in the back stack to remove")
89
+ Log.e("FragmentModule", "No fragments to remove")
81
90
  }
82
- } ?: run {
83
- // Handle the error if the activity is not a FragmentActivity
84
- Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
85
- }
86
91
  }
87
92
 
88
93
  @ReactMethod
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Video Component for TPStreams",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",