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.

Unable hide bottom sheet when click touchable

See original GitHub issue

i have bottom sheet with close button on header, but when pressed bottom sheet cannot snap to specified index given,

here my code:

import { default as React } from 'react';
import { Dimensions, StyleSheet, View } from 'react-native';
import { default as BottomSheet } from 'reanimated-bottom-sheet';
import { default as Animated } from 'react-native-reanimated';
import { Portal } from 'react-native-paper';
import { AntDesign } from '@expo/vector-icons';

import { Text, Touchable } from '../common';
import { IProduct } from '../../interface';
import { color } from '../../theme/color';

interface IAddToCartProps {
  product: IProduct;
}

const window = Dimensions.get('window');

class AddToCartSheet extends React.Component<IAddToCartProps> {
  bottomSheet = React.createRef<BottomSheet>();

  sheetOpenValue = new Animated.Value(1);

  constructor(props) {
    super(props);

    this.renderContent = this.renderContent.bind(this);
    this.renderHeader = this.renderHeader.bind(this);
    this.hideBottomSheet = this.hideBottomSheet.bind(this);
  }

  showBottomSheet(): void {
    if (this.bottomSheet.current) {
      this.bottomSheet.current.snapTo(0);
    }
  }

  hideBottomSheet(): void {
    // alert called but no snapTo
    alert('pressed')
    this.bottomSheet.current.snapTo(1)
  }

  renderHeader() {
    return (
      <View style={styles.header}>
        <Touchable borderless={true} onPress={this.hideBottomSheet}>
          <AntDesign name="close" size={21} color={color.typoMedium} />
        </Touchable>
        <Text font="Medium" style={styles.headerTitle}>
          Sesuaikan
        </Text>
      </View>
    );
  }

  renderContent() {
    return (
      <View style={styles.content}>
        <Text>wkwlland</Text>
      </View>
    );
  }

  render() {
    const { cond, greaterOrEq } = Animated;

    return (
      <Portal>
        <Animated.View
          style={[
            styles.overlay,
            {
              opacity: cond(greaterOrEq(this.sheetOpenValue, 0.95), 0, 1),
            },
          ]}
          pointerEvents="none"
        />
        <BottomSheet
          renderHeader={this.renderHeader}
          renderContent={this.renderContent}
          ref={this.bottomSheet}
          snapPoints={[350, 0]}
          initialSnap={1}
          enabledInnerScrolling={false}
          callbackNode={this.sheetOpenValue}
        />
      </Portal>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  header: {
    flexDirection: 'row',
    alignItems: 'center',
    backgroundColor: '#ffffff',
    paddingTop: 20,
    borderTopLeftRadius: 20,
    borderTopRightRadius: 20,
    height: 50,
    paddingHorizontal: 16,
    width: window.width,
  },
  headerTitle: {
    marginLeft: 16,
    fontSize: 18,
  },
  content: {
    height: 350,
    paddingTop: 20,
    backgroundColor: '#ffffff',
  },
  overlay: {
    flex: 1,
    backgroundColor: 'rgba(0,0,0, .4)',
    ...StyleSheet.absoluteFillObject,
  },
});

export { AddToCartSheet };

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
afshawnlotficommented, Sep 13, 2019

Same issue here!

1reaction
aliwaqassicommented, Jul 30, 2019

yes this problem still there and touchable does not work in android that is import from react native, if you import from react-native-gesture-handler then onPress is worked but your sheet will not be close, then for this you need to true enabledInnerScrolling prop then it works fine

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent dismissal of BottomSheetDialogFragment on touch ...
According to the BottomSheet specification bottom sheets can be dismissed by touching outside of the bottom sheet, therefore what are my options ...
Read more >
Make your BottomSheetDialog noncancelable - beta - Medium
Let's find out what makes our bottom sheets canceled first. As mentioned above there are two ways to cancel a BottomSheetDialog , by...
Read more >
React Native Bottom Sheet Tutorial with Profile Screen
In this tutorial, you'll learn how to create a bottom sheet in react native app. ... Your browser can't play this video.
Read more >
How to Close a React Native Modal with a Button - CodeProject
I used a Pressable component because I didn't want the “dimming” effect on tap when touching outside the popup that comes with the ......
Read more >
Excel for Android touch guide - Microsoft Support
Double-tap the cell, or tap in the formula bar. Add or edit cell contents. Hide the onscreen keyboard. Tap the Back key. Tab ......
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