Giter Site home page Giter Site logo

react-native-popover's Introduction

react-native-popover

npm version npm version npm licence

A <Popover> component for react-native. This is still very much a work in progress and only handles the simplest of cases, ideas and contributions are very welcome.

Demo

Install

npm i --save react-native-popover

Usage

'use strict';

var React = require('react');
var Popover = require('react-native-popover');
var {
  AppRegistry,
  StyleSheet,
  Text,
  TouchableHighlight,
  View,
} = require('react-native');

var PopoverExample = React.createClass({
  getInitialState() {
    return {
      isVisible: false,
      buttonRect: {},
    };
  },

  showPopover() {
    this.refs.button.measure((ox, oy, width, height, px, py) => {
      this.setState({
        isVisible: true,
        buttonRect: {x: px, y: py, width: width, height: height}
      });
    });
  },

  closePopover() {
    this.setState({isVisible: false});
  },

  render() {
    return (
      <View style={styles.container}>
        <TouchableHighlight ref='button' style={styles.button} onPress={this.showPopover}>
          <Text style={styles.buttonText}>Press me</Text>
        </TouchableHighlight>

        <Popover
          isVisible={this.state.isVisible}
          fromRect={this.state.buttonRect}
          onClose={this.closePopover}>
          <Text>I'm the content of this popover!</Text>
        </Popover>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'rgb(43, 186, 180)',
  },
  button: {
    borderRadius: 4,
    padding: 10,
    marginLeft: 10,
    marginRight: 10,
    backgroundColor: '#ccc',
    borderColor: '#333',
    borderWidth: 1,
  },
  buttonText: {
  }
});

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

Displaying the popover on top of other elements

React Native doesn't support directly setting a zIndex on a view. What is recommended instead is to rearrange your view hierarchy and put the popover last at the root of your app. See facebook/react-native#131

However, as an alternative, I recommend you use @brentvatne's react-native-overlay library to wrap <Popover /> and bring it to the front no matter where it sits in the render tree.

Props

Prop Type Optional Default Description
isVisible bool Yes false Show/Hide the popover
fromRect rect No {} Rectangle at which to anchor the popover
displayArea rect Yes screen rect Area where the popover is allowed to be displayed
placement string Yes 'auto' How to position the popover - top | bottom | left | right | auto. When 'auto' is specified, it will determine the ideal placement so that the popover is fully visible within displayArea.
onClose function Yes Callback to be fired when the user taps the popover
customShowHandler function Yes Custom show animation handler - uses a react-tween-state wrapper API in order to show the modal. See default show handler.
customHideHandler function Yes Custom hide animation handler - uses a react-tween-state wrapper API in order to hide the modal. See default hide handler.

rect is an object with the following properties: {x: number, y: number, width: number, height: number}

Credits

The code supporting animations was inspired and adapted from @brentvatne's Transition.js mixin.


MIT Licensed

react-native-popover's People

Contributors

jeanregisser avatar jjshammas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-popover's Issues

The Popover content sometimes doesn't appear

Sometimes the content of the Popover component doesn't appear. The 'overlay' is visible, i can close it by clicking somewhere, but the real content is invisible. I tried to give fix rect for positioning, but the issue is still there. Sadly i don't no how to reproduce the problem. Maybe an Animated issue?

Cannot use listview

It is seemingly that the library can not use the listview.Like this:

<ListView
dataSource={this.state.dataSource.cloneWithRows(this.state.data)}
renderRow={(rowData) => }
enableEmptySections={true}
/>

If I use it like this,I cannot scoll the listview.Can I use listview in popover?

[question] bridging native popover

hello, I only would like to ask if you tried to make the native ios popover available to js through native module / why you decided to make it in pure js. Thanks!

Issue with Uglify Minify

Hi – nice work!

Just one problem: I can't seem to minify my app any more. Here's the error I'm getting:

Error: Error while minifying JS
Transformed code line: " for(var placement of placementsToTry) {"
Module name (best guess): react-native-popover/Popover
Unexpected token name «of», expected punc «;» (line: 44316, col: 22, pos: 1429415)

I think it's referring to line 137 in your code:
for(var placement of placementsToTry) {

Any help would be appreciated. Thanks!

Android animation flickering

This component works on Android too, but before the animation starts, the end frame is shown briefly, causing flickering. (Using React 0.18.)

To see it more clearly, this is a recording with animations slowed down 10 times.
popover-android-slow

Margin and padding to popover area.

I am not able to give proper margin and padding to popover container. I don't want popover to be strech and touched through screen edge (full screen).

Unable to resolve module StyleSheetRegistry

Similar to this, except that it's an error which causes the build in XCode to fail.

This error occurs as of React Native 0.14.2. It works with 0.13.2.

After commenting out the code that uses StyleSheetRegistry, you'll get another similar error regarding `Dimensions'.

Android simulator stuck

In my project, the Popover works well in iOS simulator. But in android simulator, the first time I open the Popover, it works well, but when I close the Popover, the application in simulator become stuck, and the application does not response to my clicking.

breaks on React 16

Downloaded the latest branch from here but it breaks with React 16. Are there plans to maintain this for forward compatibility?

NSInvalidArgumentException on real device (not sim)

Hi,

I'm seeing the following error on a real device (iPhone 6S) but not in the simulator:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid number value (NaN) in JSON write'

The error occurs in node_modules/react-native/React/Base/RCTUtils.m:45 of react-native 0.14.2.

Any ideas what might be causing this? I was running react-native-popover on react-native 0.10 without any issues.

Thanks,

Alex

Custom animation

Hey,
I'm having issues getting the custom animation to work using startCustomAnimation. It seems like to use startCustomAnimation properly you have to use internal methods. Has anyone managed to do this in an elegant way?

Thanks

Edit: I'm using the latest version

Unable to make content appear

Hi,

I'm using react 15.2, node 5.6 and npm 3.6. I'm having no luck being able to display the content inside the popover. It appears as though the screen gets an overlay but the Popover content is nowhere to be seen.

Thank you!

Publish 0.3.0 to npm

Popover 0.2.0 is not working with React Native 0.19.0, do you plan to publish 0.3.0 on npm soon ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.