-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
android/src/main/java/com/swmansion/rnscreens/ext/ViewExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.swmansion.rnscreens.ext | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
|
||
fun View.recycle(): View { | ||
// screen fragments reuse view instances instead of creating new ones. In order to reuse a given | ||
// view it needs to be detached from the view hierarchy to allow the fragment to attach it back. | ||
this.parent?.let { parent -> | ||
(parent as ViewGroup).endViewTransition(this) | ||
parent.removeView(this) | ||
} | ||
// view detached from fragment manager get their visibility changed to GONE after their state is | ||
// dumped. Since we don't restore the state but want to reuse the view we need to change | ||
// visibility back to VISIBLE in order for the fragment manager to animate in the view. | ||
this.visibility = View.VISIBLE | ||
return this | ||
} |