2.1.0 • Published 7 years ago

react-native-simple-popover v2.1.0

Weekly downloads
67
License
MIT
Repository
github
Last release
7 years ago

react-native-simple-popover

Version NPM

react-native-simple-popover provides a simple popover implementation and supports automatic popover placement.

Installation

$ npm install react-native-simple-popover

This package does not provide native modules and does not require linking and rebuilding your application.

API

<PopoverContainer>

Provides ability for child Popover components to register and render inside this element. Child popovers are constrained by this component and render above the children.

Props

PropTypeDefaultDescription
paddingNumber0Pads component area to constrain your popovers.
childrenReactElementsnullElement tree that you want your popovers to render in.

<Popover>

Renders component with defined properties around the wrapped component.

Props

PropTypeDefaultDescription
componentComponent0Popover component to render.
isVisibleBooleantrueDefines if popover is visible.
arrowColorColor'white'Popover's arrow color.
arrowWidthNumber15Popover's arrow width.
arrowHeightNumber10Popover's arrow height.
placementString'auto'Where popover should be placed related to the wrapped component. If 'auto', all placement options are tried and first suitable placement option is picked. Supported placement options: 'left', 'right', 'top', 'bottom', 'auto'.
childrenReactElementnullElement that you want your popover to point to.
pointerEventsString'box-none'Controls whether the View can be the target of touch event. Supported options: 'auto', 'none', 'box-none' and 'box-only'.
offsetObject{ x: 0, y: 0 }Popover's offset setting.

Example

Please check Example directory for an example project with the following implementation:

import React, { Component } from 'react';
import {
  AppRegistry,
  Button,
  StyleSheet,
  Text,
  TextInput,
  View
} from 'react-native';
import { Popover, PopoverContainer } from 'react-native-simple-popover';

class Example extends Component {

  state = {
    isPopoverVisible: true,
    popoverPlacement: 'top',
  };

  render() {
    return (
      <PopoverContainer padding={20}>
        <View style={styles.container}>
          <Popover
            placement={this.state.popoverPlacement}
            arrowColor="#114B5F"
            arrowWidth={16}
            arrowHeight={8}
            isVisible={this.state.isPopoverVisible}
            component={() => (
              <View style={styles.popoverContainer}>
                <Text style={styles.popoverText}>
                  This is a very long popover text.
                  Container padding affects max width and height of this popover.
                </Text>
              </View>
            )}
          >
            <Text style={styles.welcome}>
              Welcome to React Native!
            </Text>
          </Popover>
          <View style={styles.buttons}>
            <Button
              title="Toggle Popover"
              onPress={() => {
                this.setState({ isPopoverVisible: !this.state.isPopoverVisible });
              }}
            />
            <Button
              title="Toggle Placement"
              onPress={() => {
                this.setState({
                  popoverPlacement: this.state.popoverPlacement === 'top' ? 'bottom': 'top'
                });
              }}
            />
          </View>
        </View>
      </PopoverContainer>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  buttons: {
    position: 'absolute',
    flexDirection: 'row',
    flex: 1,
    top: 0,
    left: 0,
    marginTop: 20,
  },
  popoverContainer: {
    backgroundColor: '#114B5F',
    padding: 8,
    borderRadius: 5,
  },
  popoverText: {
    color: '#E4FDE1',
  }
});

AppRegistry.registerComponent('Example', () => Example);

Example