FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: crash on Android Tab-View #6466 (#6467) · NativeScript/NativeScript@db33cf3 · GitHub

Commit db33cf3

Browse files
authored andcommitted
fix: crash on Android Tab-View #6466 (#6467)
* fix: crash on Android Tab-View #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 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
1 parent 7df8038 commit db33cf3

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎tns-core-modules/ui/tab-view/tab-view.android.ts‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,17 @@ function initializeNativeClasses() {
200200
}
201201

202202
finishUpdate(container: android.view.ViewGroup): void {
203-
if (this.mCurTransaction != null) {
204-
(<any>this.mCurTransaction).commitNowAllowingStateLoss();
205-
this.mCurTransaction = null;
206-
}
203+
this._commitCurrentTransaction();
207204
}
208205

209206
isViewFromObject(view: android.view.View, object: java.lang.Object): boolean {
210207
return (<android.support.v4.app.Fragment>object).getView() === view;
211208
}
212209

213210
saveState(): android.os.Parcelable {
211+
// Commit the current transaction on save to prevent "No view found for id 0xa" exception on restore.
212+
// Related to: https://github.com/NativeScript/NativeScript/issues/6466
213+
this._commitCurrentTransaction();
214214
return null;
215215
}
216216

@@ -221,8 +221,15 @@ function initializeNativeClasses() {
221221
getItemId(position: number): number {
222222
return position;
223223
}
224-
}
225224

225+
private _commitCurrentTransaction() {
226+
if (this.mCurTransaction != null) {
227+
this.mCurTransaction.commitNowAllowingStateLoss();
228+
this.mCurTransaction = null;
229+
}
230+
}
231+
}
232+
226233
PagerAdapter = FragmentPagerAdapter;
227234
}
228235

@@ -713,4 +720,4 @@ function tryCloneDrawable(value: android.graphics.drawable.Drawable, resources:
713720
}
714721

715722
return value;
716-
}
723+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL