Skip to content

Instantly share code, notes, and snippets.

@garrettmac
Created May 11, 2017 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettmac/7b22f5f5a01db0ad328540554fe4010a to your computer and use it in GitHub Desktop.
Save garrettmac/7b22f5f5a01db0ad328540554fe4010a to your computer and use it in GitHub Desktop.
react native plugins config
import Popover from 'react-native-popover';
this._closePopover = this._closePopover.bind(this)

in constructor

this.state{
  isVisible:false,
        buttonRect:{}
        }
_closePopover() {
    this.setState({isVisible: false});
}


_showPopover(ref) {
    console.log("  this.refs: ", this.refs);
    this.refs.popover.measure((ox, oy, width, height, px, py) => {

        this.setState({
            isVisible: true,
            buttonRect: {
                x: px,
                y: py,
                width: width,
                height: height
            }
        });
    });
}


renderButton(ref, text,icon) {
        console.log("ref: ", ref);
        console.log("text: ", text);
        let textView=<View/>;
        let iconView=<View/>;
        if(text)textView=(<Text style={{fontSize: 12,color:'white',fontWeight: 'bold'}}>{text}</Text>)
        if(icon)iconView=(<Icon name={icon}  size={20} color="#fff" />)
        return (
            <View style={{
                zIndex: 3,
                flex: 1,

            }}>
                <TouchableOpacity ref={ref}
                  style={{width:60, borderWidth:3, borderColor:'rgba(0,0,0,0.2)', alignItems:'center', justifyContent:'center', height:60, backgroundColor:'#ff585b', borderRadius:30, position:'absolute', bottom:20, right:20}}
                   onPress={this._showPopover.bind(this, ref)}>
                {textView}
                {iconView}
                </TouchableOpacity>
            </View>
        );
    }

inside render

{this.renderButton('popover','','directions-boat')}
    <Popover  isVisible={this.state.isVisible} fromRect={this.state.buttonRect} displayArea={{
                x: 100,y: 200,width: width - 10,height: height - 25
            }} onClose={this._closePopover}>
                <View style={{width: 200,height: 70,justifyContent: 'center',alignItems: 'center'}}>
                    <Text style={{color: '#ccc'}}>Content</Text>
                </View>
            </Popover>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment