question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

conditionally rendering BottomSheetBehavior doesn't show up and tapping causes crash

See original GitHub issue

RN version: 0.43.2 Library version: Latest (0.4.0)

The issue is that BottomSheetBehavior#onLayoutChild is never called, therefore mNestedScrollingChildRef in android.support.design.widget.BottomSheetBehavior is never set

Example code:


import { CoordinatorLayout, BottomSheetBehavior } from 'react-native-bottom-sheet-behavior'

class TestCase extends React.PureComponent {

  componentDidMount() {
    setTimeout(() => this.setState({ ok: true }), 5000)
  }
  
  render() {
    return (
      <CoordinatorLayout style={{flex:1}}>
        {this.state.ok && <BottomSheetBehavior
          peekHeight={70}
          hideable={false}
          state={BottomSheetBehavior.STATE_COLLAPSED}>
          <View style={{backgroundColor: '#4389f2'}}>
            <View style={{padding: 26}}>
              <Text>BottomSheetBehavior!</Text>
            </View>
            <View style={{height: 200, backgroundColor: '#fff'}} />
          </View>
        </BottomSheetBehavior> }
      </CoordinatorLayout>
    )
  }
    
}

Crashes with the following exception when you try to tap where the bottom sheet should be:

java.lang.NullPointerException: Attempt to invoke virtual method ‘java.lang.Object java.lang.ref.WeakReference.get()’ on a null object reference at android.support.design.widget.BottomSheetBehavior.onInterceptTouchEvent(BottomSheetBehavior.java:282) at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:446) at android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:485) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2366) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2456) at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2831) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1863) at android.app.Activity.dispatchTouchEvent(Activity.java:3046) at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2792) at android.view.View.dispatchPointerEvent(View.java:10233) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5397) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5233) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4673) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4726) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4692) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4834) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4700) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4891) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4673) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4726) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4692) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4700) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4673) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7359) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7237) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7198) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7469) at android.view.In

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cesardeazevedocommented, Apr 8, 2017

released at 0.5.0

0reactions
cesardeazevedocommented, Apr 8, 2017

Actually, i’ve no idea what’s going on inside yoga, but i got it, i’ve been working on the next version that supports anchor state, and i had to change a few things on the CoordinatorLayout to measure layouts correctly, so, this snippet fixes the problem. https://github.com/cesardeazevedo/react-native-bottom-sheet-behavior/blob/anchorSheet/android/src/main/java/com/bottomsheetbehavior/CoordinatorLayoutView.java#L20-L34 I am pushing a new release back to master with this change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional rendering in React Native may crash your app
Conditional rendering done wrong leads to errors in React Native that seems to jump on occasionally. Read what is happening and how to ......
Read more >
Newest 'bottom-sheet' Questions - Stack Overflow
I'm using BottomSheetScaffold to display bottom sheet where sheetContent can change it's height. Bottom Sheet behaves correctly and when content changes height ...
Read more >
A Common Conditional Rendering Bug in React Native
In the snippet above, we have a component conditionally rendering based on the “truthiness” of its string value contents, potentialTextValue ...
Read more >
Migrate your UI to responsive layouts - Android Developers
Bottom drawer using BottomSheetBehavior; Menu or popup window accessible by tapping on a menu icon. Your browser doesn't support the video tag.
Read more >
platform/frameworks/support - Git at Google
-16,27 +16,68 @@ # Don't include in unbundled build. ifeq ... + * Boolean extra that specifies whether a default share button will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found