0

I would to create a custom component to be rendered when a function is called in ReactNative. Is like a alert() component. In this case i don't want use a modal, a want to make a component that can showed in screen when a function is called. Someone have any ideia about how i can made this?

I want to make this:

const Example = () => {
    return(
        <View>
            <Button title="Show Modal" onPress={showModal}/>
        </View>
    )
}

I can't make this:

const Example = () => {
    const [isVisible, setIsVisible] = useState(false);

    return(
        <View>
            <Modal visible={isVisible}>
                <Text>Awesome code here ...</Text>
            </Modal>

            <Button title="Show Modal" onPress={() => {setIsVisible(true)}}/>
        </View>
    )
}

What i want to do is show the component whitout put her jsx in my return. I need to call a function, when this function is called my componnent is showed in screen. The logic is same of Alert.alert() function.

  • Do you have any UI reference? – rishikesh_07 Aug 26 '20 at 01:08
  • I don't have a UI reference, but will be a animated modal box thats showed when have an error in my app. Don't worry with UI, my main problem is: how to call a function and this function shows a modal box like Alert.alert() does. – Gustavo Maltez Aug 26 '20 at 01:33
  • if you want to show Alert.alert() like Ui when you have some error you can use modal and you can animate it. But according to your question, you are saying you don't want to use modal. Kindly update the question accordingly. – rishikesh_07 Aug 26 '20 at 02:19
  • Yes, you're right! I will show an example of i want make. Look the edit – Gustavo Maltez Aug 26 '20 at 11:00

0 Answers0