Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native partial modals with pan responder

I'm trying to recreate an element that appears over the screen and that can be expanded, closed or resized by a scroll gesture.

I don't know the real name of this element but it can be found in Apple Maps, Google Maps or Apple Music for example.

Examples of partial modals:

enter image description here

I have tried to create a modal screen with a transparent background and a transparent element that I resize to expand the content element but I am not satisfied at all and I'm sure there is a better way to do this.

export class PartialModal extends Component {
  this.state = {
    isFullScreen: false
  }

  render () {
    return (
      <React.Fragment>
        <TouchableWithoutFeedback onPress={() => this.props.dismiss()}>
          <Animatable.View transition='height' style={{ height: this.state.isFullScreen ? statusBarHeight : Metrics.screenHeight * 0.6 }} />
        </TouchableWithoutFeedback>
        <GestureRecognizer
          onSwipeUp={() => this.setState({ isFullScreen: true })}
          onSwipeDown={() => this.state.isFullScreen ? this.setState({ isFullScreen: false }) : this.props.dismiss()}>
          ...
        </GestureRecognizer>
      </React.Fragment>
    )
}

In this exemple, I can not expand the "modal" by dragging it, it just recognize a swipe gesture.

like image 393
piRstone Avatar asked Nov 01 '25 17:11

piRstone


2 Answers

I learned that it's called Bottom Sheet. So I searched for that and I found a few repos:

https://github.com/cesardeazevedo/react-native-bottom-sheet-behavior

https://github.com/prscX/react-native-bottom-action-sheet

I will investigate a bit more but it's a good way to start.

like image 125
piRstone Avatar answered Nov 04 '25 09:11

piRstone


Check out react-native-reanimated-bottom-sheet

You can also Check out react-navigation. And set it to modal. Then you can tweak it with cardStyleInterpolator

like image 33
Adriaan Balt Avatar answered Nov 04 '25 11:11

Adriaan Balt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!