Skip to content

[Android] Bottomsheet: app crashes when there is active button in the bottomsheet and being dismissed #8038

Closed

Description

@hamidbsd

Environment

  • CLI: 6.1.2
  • Cross-platform modules: Angular 8.2.11
  • Android Runtime: 6.1.2
  • Plugin(s): nativescript-material-components (BottomSheet) 2.5.2

Describe the bug
App crashes when touch event is being captured on the BottomSheet and the BottomSheet is being dismissed.
Has been reported on nativescript-material-components repo earlier:
nativescript-community/ui-material-components#71

To Reproduce
To reproduce, simply capture (touch) event instead of (tap) on the component being shown on the bottomsheet and it will crash when it is dismissed.

Expected behavior
Not to crash

Sample project
nativescript-material-components (BottomSheet) demo-ng

Crash Log

An uncaught Exception occurred on "main" thread.
Calling js method onDismiss failed
TypeError: Cannot read property 'setOnTouchListener' of null

StackTrace:
push.../node_modules/tns-core-modules/ui/core/view/view.js.View.onUnloaded(file:///data/data/app.name/files/app/vendor.js:102970:38)
at (file:///data/data/app.name/files/app/vendor.js:101093:92)
at push.../node_modules/tns-core-modules/ui/core/view-base/view-base.js.ViewBase.callFunctionWithSuper(file:///data/data/app.name/files/app/vendor.js:101082:9)
at push.../node_modules/tns-core-modules/ui/core/view-base/view-base.js.ViewBase.callUnloaded(file:///data/data/app.name/files/app/vendor.js:101093:14)
at push.../node_modules/tns-core-modules/ui/core/view-base/view-base.js.ViewBase.unloadView(file:///data/data/app.name/files/app/vendor.js:101222:18)
at (file:///data/data/app.name/files/app/vendor.js:101024:19)
at push.../node_modules/tns-core-modules/ui/layouts/layout-base-common.js.LayoutBaseCommon.eachChildView(file:///data/data/app.name/files/app/vendor.js:110064:26)
at push.../node_modules/tns-core-modules/ui/core/view/view-common.js.ViewCommon.eachChild(file:///data/data/app.name/files/app/vendor.js:102584:14)

Activity

  1. hamidbsd commented on Oct 30, 2019

    @hamidbsd
    ContributorAuthor
  2. tsonevn commented on Oct 31, 2019

    @tsonevn
    Contributor

    Hi @hamidbsd,
    Can you send us a sample project, where the issue, you are facing, can be reproduced?

  3. farfromrefug commented on Oct 31, 2019

    @farfromrefug
    Collaborator

    @tsonevn i asked @hamidbsd to add it here cause i already see an issue in the code:

    this.nativeViewProtected.setOnTouchListener(null);

    There you don't check for nativeViewProtected. And it might be null un unloaded.
    I think it is an edge case

    Also should i mention that it should be done in disposeNativeView and not onUnloaded

  4. hamidbsd commented on Nov 20, 2019

    @hamidbsd
    ContributorAuthor

    Here is a simple project to reproduce the crash.
    I needs {N} 6.2.1 + latest Angular + [email protected]
    https://www.dropbox.com/s/m1weedpegpo0rlv/Bottomsheet%20crashing.zip?dl=0

  5. changed the title [-][Android] Modal: app crashes when (touch) is captured in the modal and being dismissed[/-] [+][Android] Bottomsheet: app crashes when there is active button in the bottomsheet and being dismissed[/+] on Nov 21, 2019
  6. hamidbsd commented on Nov 24, 2019

    @hamidbsd
    ContributorAuthor

    @tsonevn I did what @farfromrefug suggested and it worked!
    I changed this:

    if (this.touchListenerIsSet) {
    this.nativeViewProtected.setOnTouchListener(null);
    this.touchListenerIsSet = false;
    this.nativeViewProtected.setClickable(this._isClickable);
    }

    to this:

            if (this.touchListenerIsSet) {
                this.touchListenerIsSet = false;
                if (this.nativeViewProtected) {
                    this.nativeViewProtected.setOnTouchListener(null);
                    this.nativeViewProtected.setClickable(this._isClickable);
                }
            }
    
    

    And it works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions