File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
tns-core-modules/ui/frame Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -859,7 +859,38 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
859
859
if ( traceEnabled ( ) ) {
860
860
traceWrite ( `${ fragment } .onDestroy()` , traceCategories . NativeLifecycle ) ;
861
861
}
862
+
862
863
superFunc . call ( fragment ) ;
864
+
865
+ const entry = this . entry ;
866
+ if ( ! entry ) {
867
+ traceError ( `${ fragment } .onDestroy: entry is null or undefined` ) ;
868
+ return null ;
869
+ }
870
+
871
+ const page = entry . resolvedPage ;
872
+ if ( ! page ) {
873
+ traceError ( `${ fragment } .onDestroy: entry has no resolvedPage` ) ;
874
+ return null ;
875
+ }
876
+
877
+ // fixes 'java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first'.
878
+ // on app resume in nested frame scenarios with support library version greater than 26.0.0
879
+ // HACK: this whole code block shouldn't be necessary as the native view is supposedly removed from its parent
880
+ // right after onDestroyView(...) is called but for some reason the fragment view (page) still thinks it has a
881
+ // parent while its supposed parent believes it properly removed its children; in order to "force" the child to
882
+ // lose its parent we temporarily add it to the parent, and then remove it (addViewInLayout doesn't trigger layout pass)
883
+ const nativeView = page . nativeViewProtected ;
884
+ if ( nativeView != null ) {
885
+ const parentView = nativeView . getParent ( ) ;
886
+ if ( parentView instanceof android . view . ViewGroup ) {
887
+ if ( parentView . getChildCount ( ) === 0 ) {
888
+ parentView . addViewInLayout ( nativeView , - 1 , new org . nativescript . widgets . CommonLayoutParams ( ) ) ;
889
+ }
890
+
891
+ parentView . removeView ( nativeView ) ;
892
+ }
893
+ }
863
894
}
864
895
865
896
@profile
You can’t perform that action at this time.
0 commit comments