Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PopoverTouchable undefined #20

Closed
Ashes-wzc opened this issue Mar 6, 2018 · 19 comments
Closed

PopoverTouchable undefined #20

Ashes-wzc opened this issue Mar 6, 2018 · 19 comments

Comments

@Ashes-wzc
Copy link

qq20180306-223010

@doomsower
Copy link
Owner

I need to see your jsx code where you render PopoverTouchable, otherwise I can't help

@Ashes-wzc
Copy link
Author

qq20180306-224706

also , when I try to use Popover alone , i can't see it on my device

@doomsower
Copy link
Owner

Are you sure that your imports for Popover, PopoverTouchable and Button are correct? Seems that PopoverTouchable cannot render button or popover. Maybe you're using wrong import style for button and importing module instead of component or something like it.

When you're using Popover alone, you need to set visible and fromRect props manually. Otherwise nothing is rendered. Check out PopoverTouchable source code.

@GingerBear
Copy link

GingerBear commented Mar 7, 2018

I got the same issue, I think the problem is <React.Fragment> is not supported

@doomsower
Copy link
Owner

doomsower commented Mar 7, 2018

I got the same issue, I think the problem is <React.Fragment> is not supported

In this case you have to update your react and react-native versions, or downgrade the version of this module.

@Herryjoeson
Copy link

when i use this plugins in android, is ok, but i use this plugins in ios , i get the same problem

@Herryjoeson
Copy link

image

first, i import this plugins

next i use

image

only just ios appear this problem,machine iphone 5s

@doomsower
Copy link
Owner

@Herryjoeson , what versions of react, react-native, react-native-modal-popover do you have installed in your project?

@Herryjoeson
Copy link

image
this is my versions of react,react-native and react-native-modal-popover

@Herryjoeson
Copy link

@doomsower Do I need to update the version?

@doomsower
Copy link
Owner

Please update to 0.0.6

@Herryjoeson
Copy link

ok! i will try

@Herryjoeson
Copy link

i update the version to 0.0.6, It has not been solved this problem

@doomsower
Copy link
Owner

doomsower commented Mar 9, 2018

Ok. So the error message in the first post is pretty definitive. PopoverTouchable calls its render method, somewhere inside this method it tries to render component, but instead of a component it receives some gibberish and fails to render it. Now, PopoverTouchable is very simple and can fail in 3 places:

  • React.Fragment: in case you use version of react <16.2 it will be undefined and render method should fail with exactly the same message as in the first post (in theory, haven't tried myself)
  • React.cloneElement(children[0] - cloning non-component will cause the same error as in first post
  • React.cloneElement(children[1] - second child must be popover, a default export from react-native-modal-popover. Error might pop in here if you use wrong import, e.g. import { Popover, PopoverTouchable } from './popover';. Your import is correct.

If the error is deeper in first or second child, the error message should complain about some deeper component's render method (in theory)

Btw, I checked the error message myself, and mine was a bit different from the one @Ashes-wzc got.
It also had a line about mixed-up imports. It was added in facebook/react#11505 , so he uses react <16.1.1 and therefore gets this error message because fragments were added in 16.2.

Your imports and stuff seems to be ok. This is especially strange because it works on android, because it you don't use nay platform-specific components at top level. I can only think of few reasons:

  • Screenshot of npm does not necessary match real content of npm-modules. Maybe you have something else installed, in fact. yarn list react react-native react-native-modal-popover should tell what you really have. Also maybe you red screen is a bit different OPs one. Would like to see it too.
  • Cache issues. These npm scripts should ensure you have none:
    "rc-start": "yarn start --reset-cache",
    "fresh-install": "rm -rf $TMPDIR/react-* && watchman watch-del-all && rm -rf ios/build/ModuleCache/* && rm -rf node_modules/ && rm -rf android/build && rm -rf android/app/build && rm -f yarn.lock && yarn cache clean && yarn",
    "fresh-start": "yarn run fresh-install && yarn run rc-start",

If this doesn't help, then I have no ideas and would like to get some minimal reproduction

@ggpw
Copy link

ggpw commented Mar 28, 2018

I have the same problems and have no idea how to resolve this. I use it on storybook.
here is my code, using example and modified a little

import React, {Component} from "react";
import { Dimensions, Platform, StyleSheet, StatusBar, Text, View } from 'react-native';
import Popover, { PopoverTouchable } from 'react-native-modal-popover';
import Button from 'native-base';

export default class Tooltip extends Component{

    constructor(props) {
        super(props);
        this.state = this.getState(Dimensions.get('window'));
      }
    
      componentDidMount() {
        Dimensions.addEventListener('change', this.onDimensionsChange);
      }
    
      componentWillUnmount() {
        Dimensions.removeEventListener('change', this.onDimensionsChange);
      }
    
      getState = ({ width, height }) => {
        const [dw, dh] = width > height ? [20, 40] : [40, 20];
        return {
          width: (width - dw) / 3,
          height: (height - dh) / 3,
        };
      }
      
      onDimensionsChange = ({ window }) => {
        this.setState(this.getState(window));
      }
    
      render() {
        const { width, height } = this.state;
        const { icon, text, alignItems, justifyContent, popoverStyles } = this.props;
        return (
        <View style={styles.app}>
            <PopoverTouchable onPopoverDisplayed={() => console.log('Popover displayed!')}>
              <Button onPress={() => console.log('I don\'t work')}>
                <Text>O</Text>
              </Button>
              <Popover
                contentStyle={styles.content}
                arrowStyle={styles.arrow}
                backgroundStyle={styles.background}
              >
                <Text>Hello from inside popover!</Text>
              </Popover>
            </PopoverTouchable>
          </View>
        );
    }

};

const styles = StyleSheet.create({
    app: {
      ...StyleSheet.absoluteFillObject,
      alignItems: 'center',
      justifyContent: 'center',
      backgroundColor: '#c2ffd2',
    },
    content: {
      padding: 16,
      backgroundColor: 'pink',
      borderRadius: 8,
    },
    arrow: {
      borderTopColor: 'pink',
    },
    background: {
      backgroundColor: 'rgba(0, 0, 255, 0.5)'
    },
  });

@doomsower
Copy link
Owner

@ggpw please check my previous post. I'd like to see full error message and output of yarn list react react-native react-native-modal-popover

@ggpw
Copy link

ggpw commented Mar 28, 2018

@doomsower thanks for the reply
below is output of yarn list react react-native react-native-modal-popover

yarn list v1.3.2
warning Filtering by arguments is deprecated. Please use the pattern option instead.
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 4.67s.

below are screenshots of my error
screenshot_2018-03-28-19-33-29_com affinmobile
screenshot_2018-03-28-19-35-29_com affinmobile

@doomsower
Copy link
Owner

You are using old version of react-native, which uses old react version, so this module won't work with it, because it needs React.Fragment (see details in long post above)
I plan to introduce some changes, remove the use of React.Fragment, but I need to find some time for that.

@doomsower
Copy link
Owner

I just published version 0.0.7 of this module.
There is a replacement for PopoverTouchable called PopoverController, it doesn't require React.Fragment anymore.
PopoverTouchable is still there, but I removed it from documentation and will deprecate it in future. It still requires react >16.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants