mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
* fix: crash on Android Tab-View NativeScript#6466 This fix has been tested in production with no new issues occurring. Long-term solution would be one of the following, though: 1. reintroduce overrides for `saveState`/`restoreState` in the current PagerAdapter implementation (removed on this commit NativeScript@ac04ede#diff-f1459d509d1432b432c29bcd30e462fbL97) 2. use FragmentPagerAdapter 3. use FragmentStatePagerAdapter Both 2 and 3 manage the save/restore cycles. The main difference between 2 and 3 is that 2 uses more memory, but allows for quicker switching between Fragments than 3. Since tabs should usually be limited to 5 or less, this may be the best choice to maintain performance, which is important for top level navigation tabs. When I have more time I may experiment with these options myself to see what the difference to performance and memory consumption is for each. * refactor: _commitCurrentTransaction method+comment * chore: fix typo * fix: missing class definition
This commit is contained in:

committed by
Alexander Vakrilov

parent
7df8038d09
commit
db33cf313c
@ -200,10 +200,7 @@ function initializeNativeClasses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
finishUpdate(container: android.view.ViewGroup): void {
|
finishUpdate(container: android.view.ViewGroup): void {
|
||||||
if (this.mCurTransaction != null) {
|
this._commitCurrentTransaction();
|
||||||
(<any>this.mCurTransaction).commitNowAllowingStateLoss();
|
|
||||||
this.mCurTransaction = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isViewFromObject(view: android.view.View, object: java.lang.Object): boolean {
|
isViewFromObject(view: android.view.View, object: java.lang.Object): boolean {
|
||||||
@ -211,6 +208,9 @@ function initializeNativeClasses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveState(): android.os.Parcelable {
|
saveState(): android.os.Parcelable {
|
||||||
|
// Commit the current transaction on save to prevent "No view found for id 0xa" exception on restore.
|
||||||
|
// Related to: https://github.com/NativeScript/NativeScript/issues/6466
|
||||||
|
this._commitCurrentTransaction();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +221,13 @@ function initializeNativeClasses() {
|
|||||||
getItemId(position: number): number {
|
getItemId(position: number): number {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _commitCurrentTransaction() {
|
||||||
|
if (this.mCurTransaction != null) {
|
||||||
|
this.mCurTransaction.commitNowAllowingStateLoss();
|
||||||
|
this.mCurTransaction = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PagerAdapter = FragmentPagerAdapter;
|
PagerAdapter = FragmentPagerAdapter;
|
||||||
|
Reference in New Issue
Block a user