nativescript-community / ui-material-components

Monorepo that contains all of the NativeScript Material Design plugins.
https://nativescript-community.github.io/ui-material-components/
Apache License 2.0
216 stars 80 forks source link

Tabs crash in 'handleTabStripChanged' when re-creating GridLayout #397

Open chris-praxis opened 2 years ago

chris-praxis commented 2 years ago

Make sure to check the demo app(s) for sample usage

Make sure to check the existing issues in this repository

If the demo apps cannot help and there is no issue for your problem, tell us about it

Please, ensure your title is less than 63 characters long and starts with a capital letter.

Which platform(s) does your issue occur on?

Android 12, possibly others

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

I have crash reports from users. I have not been able to reproduce, but I can see in the code how the problem can occur.

Is there any code involved?

See file: @nativescript-community/ui-material-core-tabs/tab-navigation/index.android.js

'createNativeView' calls 'handleTabStripChanged'. Crash occurs via 'handleTabStripChanged'... nativeView.removeView(this.mTabsBar);

'nativeView' was just created by caller, therefore it does not contain 'mTabsBar'. So if 'createNativeView' is ever called when 'mTabsBar' exists, then I expect it will crash. My hack-fix is to set "this.mTabsBar = null;" in 'createNativeView', prior to calling 'handleTabStripChanged', but I have not been able to verify.

Crash Info

Fatal Exception: com.tns.NativeScriptException Calling js method onCreateView failed Error: java.lang.NullPointerException: Attempt to write to field 'android.view.View org.nativescript.widgets.MeasureSpecs.child' on a null object reference

Caused by java.lang.NullPointerException Attempt to write to field 'android.view.View org.nativescript.widgets.MeasureSpecs.child' on a null object reference

handleTabStripChanged at node_modules/@nativescript-community/ui-material-core-tabs/tab-navigation/index.android.js:192:23 createNativeView at node_modules/@nativescript-community/ui-material-core-tabs/tab-navigation/index.android.js:186:17 _setupUI at node_modules/@nativescript/core/ui/core/view-base/index.js:557:30 eachChildView at node_modules/@nativescript/core/ui/content-view/index.js:65:12 eachChild at node_modules/@nativescript/core/ui/core/view/view-common.js:772:13 _setupUI at node_modules/@nativescript/core/ui/core/view-base/index.js:602:13 eachChildView at node_modules/@nativescript/core/ui/layouts/layout-base-common.js:101:27 eachChild at node_modules/@nativescript/core/ui/core/view/view-common.js:772:13 ...

chris-praxis commented 2 years ago

At least in some cases this occurs after app has been put in background and is brought back to foreground.