react-native-unified-player 0.6.5 → 0.7.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.
@@ -30,6 +30,10 @@ import android.os.Environment
30
30
  import android.view.ViewGroup
31
31
  import android.view.WindowManager
32
32
  import android.os.Build
33
+ import android.view.Gravity
34
+ import android.widget.Button
35
+ import android.graphics.drawable.GradientDrawable
36
+ import android.util.TypedValue
33
37
 
34
38
  class UnifiedPlayerView(context: Context) : FrameLayout(context) {
35
39
  companion object {
@@ -69,7 +73,9 @@ class UnifiedPlayerView(context: Context) : FrameLayout(context) {
69
73
  private var originalLayoutParams: ViewGroup.LayoutParams? = null
70
74
  private var originalParent: ViewGroup? = null
71
75
  private var originalIndex: Int = 0
72
- private var fullscreenContainer: ViewGroup? = null
76
+ private var fullscreenContainer: FrameLayout? = null
77
+ private var closeButton: Button? = null
78
+ private var isTransitioningFullscreen = false // Flag to prevent player release during fullscreen transition
73
79
 
74
80
  private val progressHandler = Handler(Looper.getMainLooper())
75
81
  private val progressRunnable: Runnable = object : Runnable {
@@ -420,9 +426,74 @@ class UnifiedPlayerView(context: Context) : FrameLayout(context) {
420
426
  // Add FLAG_KEEP_SCREEN_ON to prevent screen from turning off during playback
421
427
  activity.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
422
428
 
423
- // Simply inform React Native that we want fullscreen
424
- // The React Native side should handle hiding other UI elements
425
- Log.d(TAG, "Fullscreen mode activated - orientation changed to landscape")
429
+ // Save original parent and layout params
430
+ originalParent = parent as? ViewGroup
431
+ originalLayoutParams = layoutParams
432
+ originalIndex = originalParent?.indexOfChild(this) ?: 0
433
+
434
+ // Set flag to prevent player release during transition
435
+ isTransitioningFullscreen = true
436
+
437
+ // Remove from current parent
438
+ originalParent?.removeView(this)
439
+
440
+ // Create fullscreen container
441
+ fullscreenContainer = FrameLayout(context).apply {
442
+ setBackgroundColor(Color.BLACK)
443
+ layoutParams = FrameLayout.LayoutParams(
444
+ FrameLayout.LayoutParams.MATCH_PARENT,
445
+ FrameLayout.LayoutParams.MATCH_PARENT
446
+ )
447
+ }
448
+
449
+ // Add player to fullscreen container
450
+ fullscreenContainer?.addView(this, FrameLayout.LayoutParams(
451
+ FrameLayout.LayoutParams.MATCH_PARENT,
452
+ FrameLayout.LayoutParams.MATCH_PARENT
453
+ ))
454
+
455
+ // Create close button
456
+ closeButton = Button(context).apply {
457
+ text = "✕"
458
+ textSize = 18f
459
+ setTextColor(Color.WHITE)
460
+
461
+ // Create circular background
462
+ val drawable = GradientDrawable().apply {
463
+ shape = GradientDrawable.OVAL
464
+ setColor(Color.argb(128, 0, 0, 0)) // Semi-transparent black
465
+ }
466
+ background = drawable
467
+
468
+ // Set button size (44dp x 44dp for touch target)
469
+ val buttonSize = TypedValue.applyDimension(
470
+ TypedValue.COMPLEX_UNIT_DIP, 44f, resources.displayMetrics
471
+ ).toInt()
472
+
473
+ layoutParams = FrameLayout.LayoutParams(buttonSize, buttonSize).apply {
474
+ gravity = Gravity.TOP or Gravity.END
475
+ val margin = TypedValue.applyDimension(
476
+ TypedValue.COMPLEX_UNIT_DIP, 16f, resources.displayMetrics
477
+ ).toInt()
478
+ setMargins(margin, margin, margin, margin)
479
+ }
480
+
481
+ setOnClickListener {
482
+ setIsFullscreen(false)
483
+ }
484
+ }
485
+
486
+ // Add close button to fullscreen container
487
+ fullscreenContainer?.addView(closeButton)
488
+
489
+ // Add fullscreen container to the decor view (root)
490
+ val decorView = activity.window.decorView as? ViewGroup
491
+ decorView?.addView(fullscreenContainer)
492
+
493
+ // Reset transition flag
494
+ isTransitioningFullscreen = false
495
+
496
+ Log.d(TAG, "Fullscreen mode activated - player moved to fullscreen container")
426
497
  }
427
498
 
428
499
  private fun exitFullscreen(activity: Activity) {
@@ -445,7 +516,36 @@ class UnifiedPlayerView(context: Context) : FrameLayout(context) {
445
516
  // Remove FLAG_KEEP_SCREEN_ON
446
517
  activity.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
447
518
 
448
- Log.d(TAG, "Fullscreen mode exited - orientation restored")
519
+ // Set flag to prevent player release during transition
520
+ isTransitioningFullscreen = true
521
+
522
+ // Remove player from fullscreen container
523
+ fullscreenContainer?.removeView(this)
524
+
525
+ // Remove fullscreen container from decor view
526
+ val decorView = activity.window.decorView as? ViewGroup
527
+ fullscreenContainer?.let { container ->
528
+ decorView?.removeView(container)
529
+ }
530
+
531
+ // Restore player to original parent
532
+ originalParent?.let { parent ->
533
+ // Add back at original index with original layout params
534
+ originalLayoutParams?.let { params ->
535
+ parent.addView(this, originalIndex.coerceAtMost(parent.childCount), params)
536
+ } ?: parent.addView(this, originalIndex.coerceAtMost(parent.childCount))
537
+ }
538
+
539
+ // Reset transition flag
540
+ isTransitioningFullscreen = false
541
+
542
+ // Clean up references
543
+ closeButton = null
544
+ fullscreenContainer = null
545
+ originalParent = null
546
+ originalLayoutParams = null
547
+
548
+ Log.d(TAG, "Fullscreen mode exited - player restored to original position")
449
549
  }
450
550
 
451
551
  fun play() {
@@ -602,7 +702,14 @@ class UnifiedPlayerView(context: Context) : FrameLayout(context) {
602
702
 
603
703
  override fun onDetachedFromWindow() {
604
704
  super.onDetachedFromWindow()
605
- Log.d(TAG, "UnifiedPlayerView onDetachedFromWindow")
705
+ Log.d(TAG, "UnifiedPlayerView onDetachedFromWindow, isTransitioningFullscreen: $isTransitioningFullscreen")
706
+
707
+ // Don't release player during fullscreen transitions
708
+ if (isTransitioningFullscreen) {
709
+ Log.d(TAG, "Skipping player release - fullscreen transition in progress")
710
+ return
711
+ }
712
+
606
713
  stopProgressUpdates() // Stop progress updates
607
714
  player?.release()
608
715
  player = null // Ensure player is nullified
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unified-player",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "Unified Player",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",