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

Toast dosen't show in android in RN6.2.0 #124

Open
liwenkangatom opened this issue Apr 26, 2020 · 15 comments
Open

Toast dosen't show in android in RN6.2.0 #124

liwenkangatom opened this issue Apr 26, 2020 · 15 comments

Comments

@liwenkangatom
Copy link

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

@sunnylqm
Copy link
Collaborator

sunnylqm commented Apr 26, 2020

magicismight/react-native-root-siblings#62 (comment)

@sunnylqm sunnylqm pinned this issue Apr 29, 2020
@Merlier
Copy link

Merlier commented Apr 29, 2020

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;

@tuladharjaa
Copy link

Yes I am also having the same problem on RN 0.62.2

@cybercoder
Copy link

me too.

@Merlier
Copy link

Merlier commented May 5, 2020

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;

@BeardedUncle
Copy link

me too.

@sunnylqm
Copy link
Collaborator

sunnylqm commented May 6, 2020

Nobody see this? #124 (comment)

@liukefu2050
Copy link

liukefu2050 commented May 18, 2020

I fix it use wrap the App.js

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

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

thanks @sunnylqm

@ShepelE
Copy link

ShepelE commented May 26, 2020

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

@huaiguoguo
Copy link

me too

@huaiguoguo
Copy link

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 ?

@rockvic
Copy link

rockvic commented Jun 9, 2020

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.

@irondsd
Copy link

irondsd commented Jun 19, 2020

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.

@sunnylqm
Copy link
Collaborator

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

@nympheastudio
Copy link

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);

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