fix(android): edge cases and compatibility with fragments 1.2.x (#9782)

This commit is contained in:
Eduardo Speroni
2022-02-17 23:36:54 -03:00
committed by Nathan Walker
parent b553a900d7
commit 6b41268a08
3 changed files with 17 additions and 4 deletions

View File

@ -342,6 +342,7 @@ function getTransitionListener(entry: ExpandedEntry, transition: androidx.transi
public onTransitionStart(transition: androidx.transition.Transition): void {
const entry = this.entry;
entry.isAnimationRunning = true;
addToWaitingQueue(entry);
if (Trace.isEnabled()) {
Trace.write(`START ${toShortString(transition)} transition for ${entry.fragmentTag}`, Trace.categories.Transition);
@ -353,6 +354,7 @@ function getTransitionListener(entry: ExpandedEntry, transition: androidx.transi
if (Trace.isEnabled()) {
Trace.write(`END ${toShortString(transition)} transition for ${entry.fragmentTag}`, Trace.categories.Transition);
}
entry.isAnimationRunning = false;
transitionOrAnimationCompleted(entry, this.backEntry);
}
@ -370,6 +372,8 @@ function getTransitionListener(entry: ExpandedEntry, transition: androidx.transi
}
onTransitionCancel(transition: androidx.transition.Transition): void {
const entry = this.entry;
entry.isAnimationRunning = false;
if (Trace.isEnabled()) {
Trace.write(`CANCEL ${toShortString(transition)} transition for ${this.entry.fragmentTag}`, Trace.categories.Transition);
}

View File

@ -1024,9 +1024,13 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
// we depend on the animation (even None animation) to set the entry as the current entry
// animation should start between start and resume, so if we have an executing navigation here it probably means the animation was skipped
// so we manually set the entry
// also, to be compatible with fragments 1.2.x we need this setTimeout as animations haven't run on onResume yet
setTimeout(() => {
if (frame._executingContext && !(<any>this.entry).isAnimationRunning) {
frame.setCurrent(this.entry, frame._executingContext.navigationType);
}
}, 0);
superFunc.call(fragment);
}

View File

@ -136,6 +136,9 @@ function initializeNativeClasses() {
public items: Array<TabViewItemDefinition>;
private mCurTransaction: androidx.fragment.app.FragmentTransaction;
private mCurrentPrimaryItem: androidx.fragment.app.Fragment;
// in fragments 1.3+, committing a transaction may call the adapter's methods and trigger another commit
// we prevent that here.
private transactionRunning = false;
constructor(public owner: TabView) {
super();
@ -270,8 +273,10 @@ function initializeNativeClasses() {
}
private _commitCurrentTransaction() {
if (this.mCurTransaction != null) {
if (this.mCurTransaction != null && !this.transactionRunning) {
this.transactionRunning = true;
this.mCurTransaction.commitNowAllowingStateLoss();
this.transactionRunning = false;
this.mCurTransaction = null;
}
}