mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-04 21:06:45 +08:00
fix(android): edge cases and compatibility with fragments 1.2.x (#9782)
This commit is contained in:
committed by
Nathan Walker
parent
b553a900d7
commit
6b41268a08
@ -342,6 +342,7 @@ function getTransitionListener(entry: ExpandedEntry, transition: androidx.transi
|
|||||||
|
|
||||||
public onTransitionStart(transition: androidx.transition.Transition): void {
|
public onTransitionStart(transition: androidx.transition.Transition): void {
|
||||||
const entry = this.entry;
|
const entry = this.entry;
|
||||||
|
entry.isAnimationRunning = true;
|
||||||
addToWaitingQueue(entry);
|
addToWaitingQueue(entry);
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(`START ${toShortString(transition)} transition for ${entry.fragmentTag}`, Trace.categories.Transition);
|
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()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(`END ${toShortString(transition)} transition for ${entry.fragmentTag}`, Trace.categories.Transition);
|
Trace.write(`END ${toShortString(transition)} transition for ${entry.fragmentTag}`, Trace.categories.Transition);
|
||||||
}
|
}
|
||||||
|
entry.isAnimationRunning = false;
|
||||||
transitionOrAnimationCompleted(entry, this.backEntry);
|
transitionOrAnimationCompleted(entry, this.backEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,6 +372,8 @@ function getTransitionListener(entry: ExpandedEntry, transition: androidx.transi
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTransitionCancel(transition: androidx.transition.Transition): void {
|
onTransitionCancel(transition: androidx.transition.Transition): void {
|
||||||
|
const entry = this.entry;
|
||||||
|
entry.isAnimationRunning = false;
|
||||||
if (Trace.isEnabled()) {
|
if (Trace.isEnabled()) {
|
||||||
Trace.write(`CANCEL ${toShortString(transition)} transition for ${this.entry.fragmentTag}`, Trace.categories.Transition);
|
Trace.write(`CANCEL ${toShortString(transition)} transition for ${this.entry.fragmentTag}`, Trace.categories.Transition);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1024,9 +1024,13 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
|
|||||||
// we depend on the animation (even None animation) to set the entry as the current entry
|
// 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
|
// 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
|
// so we manually set the entry
|
||||||
if (frame._executingContext && !(<any>this.entry).isAnimationRunning) {
|
// also, to be compatible with fragments 1.2.x we need this setTimeout as animations haven't run on onResume yet
|
||||||
frame.setCurrent(this.entry, frame._executingContext.navigationType);
|
setTimeout(() => {
|
||||||
}
|
if (frame._executingContext && !(<any>this.entry).isAnimationRunning) {
|
||||||
|
frame.setCurrent(this.entry, frame._executingContext.navigationType);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
|
||||||
superFunc.call(fragment);
|
superFunc.call(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -136,6 +136,9 @@ function initializeNativeClasses() {
|
|||||||
public items: Array<TabViewItemDefinition>;
|
public items: Array<TabViewItemDefinition>;
|
||||||
private mCurTransaction: androidx.fragment.app.FragmentTransaction;
|
private mCurTransaction: androidx.fragment.app.FragmentTransaction;
|
||||||
private mCurrentPrimaryItem: androidx.fragment.app.Fragment;
|
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) {
|
constructor(public owner: TabView) {
|
||||||
super();
|
super();
|
||||||
@ -270,8 +273,10 @@ function initializeNativeClasses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _commitCurrentTransaction() {
|
private _commitCurrentTransaction() {
|
||||||
if (this.mCurTransaction != null) {
|
if (this.mCurTransaction != null && !this.transactionRunning) {
|
||||||
|
this.transactionRunning = true;
|
||||||
this.mCurTransaction.commitNowAllowingStateLoss();
|
this.mCurTransaction.commitNowAllowingStateLoss();
|
||||||
|
this.transactionRunning = false;
|
||||||
this.mCurTransaction = null;
|
this.mCurTransaction = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user