react-native-modalbox icon indicating copy to clipboard operation
react-native-modalbox copied to clipboard

Need 'left' and 'right' in entry props!

Open KinanKazmi opened this issue 8 years ago • 11 comments

Anyway to use this as a Side Menu? Like i could use 'left' or 'right' in 'entry' prop and bring it from the side?

KinanKazmi avatar Sep 09 '16 10:09 KinanKazmi

with abit of math, you could achieve 'left or right position'.

Try setting below to achieve 'right position'

position='top'
styles= {{
    height: 50,
    width: x,
    marginLeft: (width - x) / 2,
}}

This will simulate a top right modal.

holyxiaoxin avatar Sep 12 '16 08:09 holyxiaoxin

I changed his render() to this.

  render: function() {
    var visible     = this.state.isOpen || this.state.isAnimateOpen || this.state.isAnimateClose;
    var size        = {height: this.state.containerHeight, width: this.state.containerWidth};
    var offsetX     = (this.state.containerWidth - this.state.width) / 2;
    var offsetY     = (this.state.containerWidth - this.state.width) / 2;
    var backdrop    = this.renderBackdrop(size);

    if (!visible) return <View/>

      var Tr;
      if (this.props.entry === 'left')
        Tr = [{translateX: this.state.position}, {translateY: offsetY}]
      else if (this.props.entry === 'right')
        Tr = [{translateX: this.state.position}, {translateY: offsetY}];
      else if (this.props.entry === 'top')
        Tr = [{translateY: this.state.position}, {translateX: offsetX}];
      else
        Tr = [{translateY: this.state.position}, {translateX: offsetX}];

    return (
      <View style={[styles.transparent, styles.absolute]} pointerEvents={'box-none'} onLayout={this.onContainerLayout}>
        {backdrop}
        <Animated.View
         onLayout={this.onViewLayout}
         style={[styles.wrapper, size, this.props.style, {transform: Tr} ]}
         {...this.state.pan.panHandlers}>
          {this.props.children}
        </Animated.View>
      </View>
    );
  },

Similarly, added 'x' related stuff to link with props of 'left' and 'right'

KinanKazmi avatar Sep 12 '16 09:09 KinanKazmi

This component hasn't been developed to be used as a side menu though... Maybe you could use one of the many side-menu components available

maxs15 avatar Sep 12 '16 14:09 maxs15

Nah man, it works perfectly like one, with my modifications. It would be better if you did it though.

KinanKazmi avatar Sep 12 '16 17:09 KinanKazmi

Plus, people could want the left/right entry for the modalbox too.

KinanKazmi avatar Sep 12 '16 17:09 KinanKazmi

And modalbox's flexibility and animation is why i prefer it over other side menus.

KinanKazmi avatar Sep 12 '16 17:09 KinanKazmi

So, would you formally do it? Or should i just keep using it with my own modifications?

KinanKazmi avatar Sep 15 '16 07:09 KinanKazmi

The community side menu and drawer components are designed to act as routers which rules them out for my project. They also have trouble integrating with NavigationExperimental. I'm looking for a component that is fully independent of the router, so thanks to @KinanKazmi for sharing his solution.

@maxs15 Would you be interested in a PR that implements left/right positions?

peacechen avatar Feb 28 '17 14:02 peacechen

Sure @peacechen, with an example in the Example project it would be perfect 👍

maxs15 avatar Feb 28 '17 14:02 maxs15

would also love to have this improvement. Is there a fork available with this functionality?

macrozone avatar Aug 29 '17 11:08 macrozone

I used the prop entry with the value 'left'.

https://github.com/AugustusCosta/react-native-modalbox

AugustusCosta avatar Jun 08 '19 01:06 AugustusCosta