Skip to content

Commit 05e7f2b

Browse files
authored
Merge pull request #1 from fpm-git/fix/exit-pip-layout
Reference original parent, layout params for PiP
2 parents 4fe483d + a4da299 commit 05e7f2b

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ public class ReactExoplayerView extends FrameLayout implements
272272

273273
private CmcdConfiguration.Factory cmcdConfigurationFactory;
274274

275+
private ViewGroup originalParent;
276+
private LayoutParams originalLayoutParams;
277+
275278
public void setCmcdConfigurationFactory(CmcdConfiguration.Factory factory) {
276279
this.cmcdConfigurationFactory = factory;
277280
}
@@ -2276,29 +2279,39 @@ protected void setIsInPictureInPicture(boolean isInPictureInPicture) {
22762279
View decorView = currentActivity.getWindow().getDecorView();
22772280
ViewGroup rootView = decorView.findViewById(android.R.id.content);
22782281

2279-
LayoutParams layoutParams = new LayoutParams(
2280-
LayoutParams.MATCH_PARENT,
2281-
LayoutParams.MATCH_PARENT);
2282-
22832282
if (isInPictureInPicture) {
2284-
ViewGroup parent = (ViewGroup)exoPlayerView.getParent();
2285-
if (parent != null) {
2286-
parent.removeView(exoPlayerView);
2287-
}
2283+
// Store original parent and layout params
2284+
originalParent = (ViewGroup)exoPlayerView.getParent();
2285+
originalLayoutParams = (LayoutParams)exoPlayerView.getLayoutParams();
2286+
2287+
if (originalParent != null) {
2288+
originalParent.removeView(exoPlayerView);
2289+
}
2290+
22882291
for (int i = 0; i < rootView.getChildCount(); i++) {
22892292
if (rootView.getChildAt(i) != exoPlayerView) {
22902293
rootViewChildrenOriginalVisibility.add(rootView.getChildAt(i).getVisibility());
22912294
rootView.getChildAt(i).setVisibility(View.GONE);
22922295
}
22932296
}
2294-
rootView.addView(exoPlayerView, layoutParams);
2297+
2298+
LayoutParams pipParams = new LayoutParams(
2299+
LayoutParams.MATCH_PARENT,
2300+
LayoutParams.MATCH_PARENT);
2301+
rootView.addView(exoPlayerView, pipParams);
22952302
} else {
22962303
rootView.removeView(exoPlayerView);
22972304
if (!rootViewChildrenOriginalVisibility.isEmpty()) {
22982305
for (int i = 0; i < rootView.getChildCount(); i++) {
22992306
rootView.getChildAt(i).setVisibility(rootViewChildrenOriginalVisibility.get(i));
23002307
}
2301-
addView(exoPlayerView, 0, layoutParams);
2308+
2309+
// Restore original parent and layout params
2310+
if (originalParent != null) {
2311+
originalParent.addView(exoPlayerView, originalLayoutParams);
2312+
// Force layout update
2313+
reLayoutControls();
2314+
}
23022315
}
23032316
}
23042317
}

0 commit comments

Comments
 (0)