| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,10 @@ | |||
| 1 | 1 | import { AndroidFragmentCallbacks, setFragmentCallbacks, setFragmentClass } from "./frame"; | |
| 2 | 2 | ||
| 3 | 3 | @JavaProxy("com.tns.FragmentClass") | |
| 4 | - class FragmentClass extends android.support.v4.app.Fragment { | ||
| 4 | + class FragmentClass extends org.nativescript.widgets.FragmentBase { | ||
| 5 | 5 | // This field is updated in the frame module upon `new` (although hacky this eases the Fragment->callbacks association a lot) | |
| 6 | 6 | private _callbacks: AndroidFragmentCallbacks; | |
| 7 | - | ||
| 7 | + | ||
| 8 | 8 | constructor() { | |
| 9 | 9 | super(); | |
| 10 | 10 | return global.__native(this); | |
@@ -15,8 +15,7 @@ class FragmentClass extends android.support.v4.app.Fragment { | |||
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | 17 | public onCreateAnimator(transit: number, enter: boolean, nextAnim: number): android.animation.Animator { | |
| 18 | - let result = this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator); | ||
| 19 | - return result; | ||
| 18 | + return this._callbacks.onCreateAnimator(this, transit, enter, nextAnim, super.onCreateAnimator); | ||
| 20 | 19 | } | |
| 21 | 20 | ||
| 22 | 21 | public onStop(): void { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,20 @@ export function _setAndroidFragmentTransitions( | |||
| 86 | 86 | name = navigationTransition.name ? navigationTransition.name.toLowerCase() : ""; | |
| 87 | 87 | } | |
| 88 | 88 | ||
| 89 | - let useLollipopTransition = name && (name.indexOf("slide") === 0 || name === "fade" || name === "explode") && sdkVersion() >= 21; | ||
| 89 | + let useLollipopTransition = !!(name && (name.indexOf("slide") === 0 || name === "fade" || name === "explode") && sdkVersion() >= 21); | ||
| 90 | + // [nested frames / fragments] force disable lollipop transitions in case nested fragments | ||
| 91 | + // are detected as applying dummy animator to the nested fragment with the same duration as | ||
| 92 | + // the exit animator of the removing parent fragment as a workaround for | ||
| 93 | + // https://code.google.com/p/android/issues/detail?id=55228 works only if custom animations are | ||
| 94 | + // used | ||
| 95 | + // NOTE: this effectively means you cannot use Explode transition in nested frames scenarios as | ||
| 96 | + // we have implementations only for slide, fade, and flip | ||
| 97 | + if (currentFragment && | ||
| 98 | + currentFragment.getChildFragmentManager() && | ||
| 99 | + currentFragment.getChildFragmentManager().getFragments().toArray().length > 0) { | ||
| 100 | + useLollipopTransition = false; | ||
| 101 | + } | ||
| 102 | + | ||
| 90 | 103 | if (!animated) { | |
| 91 | 104 | name = "none"; | |
| 92 | 105 | } else if (transition) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -457,8 +457,8 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition { | |||
| 457 | 457 | } | |
| 458 | 458 | ||
| 459 | 459 | public _onRootViewReset(): void { | |
| 460 | - this._removeFromFrameStack(); | ||
| 461 | 460 | super._onRootViewReset(); | |
| 461 | + this._removeFromFrameStack(); | ||
| 462 | 462 | } | |
| 463 | 463 | ||
| 464 | 464 | get _childrenCount(): number { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,8 +209,12 @@ export class Frame extends FrameBase { | |||
| 209 | 209 | } | |
| 210 | 210 | ||
| 211 | 211 | public _onRootViewReset(): void { | |
| 212 | - this.disposeCurrentFragment(); | ||
| 213 | 212 | super._onRootViewReset(); | |
| 213 | + | ||
| 214 | + // call this AFTER the super call to ensure descendants apply their rootview-reset logic first | ||
| 215 | + // i.e. in a scenario with nested frames / frame with tabview let the descendandt cleanup the inner | ||
| 216 | + // fragments first, and then cleanup the parent fragments | ||
| 217 | + this.disposeCurrentFragment(); | ||
| 214 | 218 | } | |
| 215 | 219 | ||
| 216 | 220 | onUnloaded() { | |
@@ -223,11 +227,6 @@ export class Frame extends FrameBase { | |||
| 223 | 227 | } | |
| 224 | 228 | ||
| 225 | 229 | private disposeCurrentFragment(): void { | |
| 226 | - // when interacting with nested fragments it seems Android is smart enough | ||
| 227 | - // to automatically remove child fragments when parent fragment is removed; | ||
| 228 | - // however, we must add a fragment.isAdded() guard as our logic will try to | ||
| 229 | - // explicitly remove the already removed child fragment causing an | ||
| 230 | - // IllegalStateException: Fragment has not been attached yet. | ||
| 231 | 230 | if (!this._currentEntry || | |
| 232 | 231 | !this._currentEntry.fragment || | |
| 233 | 232 | !this._currentEntry.fragment.isAdded()) { | |
@@ -742,7 +741,13 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { | |||
| 742 | 741 | } | |
| 743 | 742 | ||
| 744 | 743 | @profile | |
| 745 | - public onCreateAnimator(fragment: android.support.v4.app.Fragment, transit: number, enter: boolean, nextAnim: number, superFunc: Function): android.animation.Animator { | ||
| 744 | + public onCreateAnimator(fragment: org.nativescript.widgets.FragmentBase, transit: number, enter: boolean, nextAnim: number, superFunc: Function): android.animation.Animator { | ||
| 745 | + // HACK: FragmentBase class MUST handle removing nested fragment scenario to workaround | ||
| 746 | + // https://code.google.com/p/android/issues/detail?id=55228 | ||
| 747 | + if (!enter && fragment.getRemovingParentFragment()) { | ||
| 748 | + return superFunc.call(fragment, transit, enter, nextAnim); | ||
| 749 | + } | ||
| 750 | + | ||
| 746 | 751 | let nextAnimString: string; | |
| 747 | 752 | switch (nextAnim) { | |
| 748 | 753 | case AnimationType.enterFakeResourceId: nextAnimString = "enter"; break; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,7 @@ function initializeNativeClasses() { | |||
| 45 | 45 | return; | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 48 | - class TabFragmentImplementation extends android.support.v4.app.Fragment { | ||
| 48 | + class TabFragmentImplementation extends org.nativescript.widgets.FragmentBase { | ||
| 49 | 49 | private tab: TabView; | |
| 50 | 50 | private index: number; | |
| 51 | 51 | ||
@@ -55,7 +55,6 @@ function initializeNativeClasses() { | |||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | static newInstance(tabId: number, index: number): TabFragmentImplementation { | |
| 58 | - | ||
| 59 | 58 | const args = new android.os.Bundle(); | |
| 60 | 59 | args.putInt(TABID, tabId); | |
| 61 | 60 | args.putInt(INDEX, index); | |
@@ -79,10 +78,6 @@ function initializeNativeClasses() { | |||
| 79 | 78 | ||
| 80 | 79 | return tabItem.view.nativeViewProtected; | |
| 81 | 80 | } | |
| 82 | - | ||
| 83 | - public onDestroyView() { | ||
| 84 | - super.onDestroyView(); | ||
| 85 | - } | ||
| 86 | 81 | } | |
| 87 | 82 | ||
| 88 | 83 | const POSITION_UNCHANGED = -1; | |
@@ -560,8 +555,13 @@ export class TabView extends TabViewBase { | |||
| 560 | 555 | } | |
| 561 | 556 | ||
| 562 | 557 | public _onRootViewReset(): void { | |
| 563 | - this.disposeCurrentFragments(); | ||
| 564 | 558 | super._onRootViewReset(); | |
| 559 | + | ||
| 560 | + // call this AFTER the super call to ensure descendants apply their rootview-reset logic first | ||
| 561 | + // i.e. in a scenario with tab frames let the frames cleanup their fragments first, and then | ||
| 562 | + // cleanup the tab fragments to avoid | ||
| 563 | + // android.content.res.Resources$NotFoundException: Unable to find resource ID #0xfffffff6 | ||
| 564 | + this.disposeCurrentFragments(); | ||
| 565 | 565 | } | |
| 566 | 566 | ||
| 567 | 567 | private disposeCurrentFragments(): void { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -164,6 +164,12 @@ | |||
| 164 | 164 | public verticalAlignment: VerticalAlignment; | |
| 165 | 165 | } | |
| 166 | 166 | ||
| 167 | + export class FragmentBase extends android.support.v4.app.Fragment { | ||
| 168 | + constructor(); | ||
| 169 | + | ||
| 170 | + public getRemovingParentFragment(): android.support.v4.app.Fragment; | ||
| 171 | + } | ||
| 172 | + | ||
| 167 | 173 | export enum Stretch { | |
| 168 | 174 | none, | |
| 169 | 175 | aspectFill, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments