react-native-root-toast icon indicating copy to clipboard operation
react-native-root-toast copied to clipboard

Toast dosen't show in android in RN6.2.0

Open liwenkangatom opened this issue 5 years ago • 15 comments

ios is work only anroid.like eact-native-root-sibling problem #

liwenkangatom avatar Apr 26 '20 09:04 liwenkangatom

https://github.com/magicismight/react-native-root-siblings/issues/62#issuecomment-609889432

sunnylqm avatar Apr 26 '20 09:04 sunnylqm

I have the same issue. Since the upgrade to RN0.62.2, toast doesn't show in both calling api or component.

There's something when you fix, in the code below, the useState "isVisible" to true at the start, the toast is shown one time and then no more when you click the button.

Packages:

npmPackages: "react": "16.11.0", "react-native": "0.62.2", "react-native-root-toast": "^3.2.1"

Code:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */
import React, {useState} from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import Toast from 'react-native-root-toast';

function HomeScreen(props) {
  const [isVisible, setVisible] = useState(false);
  return (
    <View>
      <Button
        title="TEST"
        onPress={() => {
          setVisible(!isVisible);

          // Add a Toast on screen.
          let toast = Toast.show('Success', {
            backgroundColor: 'green',
            opacity: 1,
            duration: Toast.durations.LONG,
            position: Toast.positions.BOTTOM,
            shadow: true,
            animation: true,
            hideOnPress: true,
            delay: 0,
            onShow: () => {
              // calls on toast\`s appear animation start
            },
            onShown: () => {
              // calls on toast\`s appear animation end.
            },
            onHide: () => {
              // calls on toast\`s hide animation start.
            },
            onHidden: () => {
              // calls on toast\`s hide animation end.
            },
          });
        }}
      />
      <Toast
        visible={isVisible}
        position={50}
        shadow={false}
        animation={false}
        hideOnPress={true}>
        This is a message
      </Toast>
      <Text style={{textAlign: 'center'}}>
        {isVisible ? 'Toast visible' : 'Toast hidden'}
      </Text>
    </View>
  );
}

const App: () => React$Node = () => {
  return <HomeScreen />;
};

const styles = StyleSheet.create({});

export default App;

Merlier avatar Apr 29 '20 14:04 Merlier

Yes I am also having the same problem on RN 0.62.2

tuladharjaa avatar May 01 '20 07:05 tuladharjaa

me too.

cybercoder avatar May 04 '20 20:05 cybercoder

I've found a temporary solution. As the issue comes from the react-native-root-siblings module and the ToastContainer component is exported (see here), we can just use the ToastContainer component.

Code example:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

import React, {useState} from 'react';
import {StyleSheet, View, Text, Button} from 'react-native';
import {ToastContainer} from 'react-native-root-toast';

function HomeScreen(props) {
  const [isVisible, setVisible] = useState(true);

  return (
    <View>
      <Button
        title="TEST"
        onPress={() => {
          setVisible(!isVisible);
        }}
      />
      <ToastContainer
        visible={isVisible}
        backgroundColor={'red'}
        opacity={1}
        shadow={true}
        animation={true}
        hideOnPress={true}
        delay={0}
        onHidden={() => {
          console.log('onHidden');
        }}>
        This is a message
      </ToastContainer>
      <Text style={{textAlign: 'center'}}>
        {isVisible ? 'Toast visible' : 'Toast hidden'}
      </Text>
    </View>
  );
}

const App: () => React$Node = () => {
  return <HomeScreen />;
};

const styles = StyleSheet.create({});

export default App;

Merlier avatar May 05 '20 12:05 Merlier

me too.

BeardedUncle avatar May 06 '20 10:05 BeardedUncle

Nobody see this? https://github.com/magicismight/react-native-root-toast/issues/124#issuecomment-619519865

sunnylqm avatar May 06 '20 11:05 sunnylqm

I fix it use <RootSiblingParent> wrap the App.js

import {RootSiblingParent} from 'react-native-root-siblings'

        <Provider store = {store} >
            <RootSiblingParent>
                <App />
            </RootSiblingParent>
        </Provider>

thanks @sunnylqm

liukefu2050 avatar May 18 '20 05:05 liukefu2050

I've paid my attention that in my case toasts are not shown only for android dev build. So I can debug toasts on ios, and then they are shown for both platforms in prod build

Hope that will help you

ShepelE avatar May 26 '20 10:05 ShepelE

me too

huaiguoguo avatar May 30 '20 08:05 huaiguoguo

I fix it use wrap the App.js

import {RootSiblingParent} from 'react-native-root-siblings'

        <Provider store = {store} >
            <RootSiblingParent>
                <App />
            </RootSiblingParent>
        </Provider>

thanks @sunnylqm

thanks , its working, but why ?

huaiguoguo avatar May 30 '20 08:05 huaiguoguo

I fix it use wrap the App.js

import {RootSiblingParent} from 'react-native-root-siblings'

        <Provider store = {store} >
            <RootSiblingParent>
                <App />
            </RootSiblingParent>
        </Provider>

thanks @sunnylqm

thanks, it's working for me.

rockvic avatar Jun 09 '20 08:06 rockvic

I fix it use wrap the App.js

import {RootSiblingParent} from 'react-native-root-siblings'

        <Provider store = {store} >
            <RootSiblingParent>
                <App />
            </RootSiblingParent>
        </Provider>

thanks @sunnylqm

It worked for me as well. Even though I don't like that I have to install a separate library only to fix an issue. I hope it gets fixed.

irondsd avatar Jun 19 '20 18:06 irondsd

It's not a separate library. It's a dependency.

sunnylqm avatar Jun 20 '20 00:06 sunnylqm

i still have the problem. so for now i do this 👍 let m="message";"ios"===Platform.OS?Toast.show(m,Toast.SHORT):ToastAndroid.show(m,ToastAndroid.SHORT);

nympheastudio avatar Jun 08 '22 23:06 nympheastudio