如何使用反应式闪光与反应式启动



我正在使用wix的反应基本运动,我想使用react-native-native-flash-message。在官方文档https://www.npmjs.com/package/reaeact-native-flash-message中,他们给出了我们可以在全球和本地使用,但在我的代码中,我没有得到我应该使用的地方。

以下是我的代码。

这是我的app.js

import { Navigation } from "react-native-navigation";
import { Provider } from "react-redux";
import registerScreens from './components/Screens'
import Icon from 'react-native-vector-icons/FontAwesome';
import configureStore from "./store/configureStore";
const store = configureStore();
registerScreens(Provider, store);
// Start a App
Navigation.events().registerAppLaunchedListener(() => {
    Promise.all([
        Icon.getImageSource("bars", 30, 'black'),
        Icon.getImageSource("share-alt", 30, 'black')
    ]).then(sources => {
        Navigation.setRoot({
            root: {
                sideMenu: {
                    left: {
                        component: {
                            name: 'app.NavigationDrawer',
                            passProps: {
                                text: 'This is a left side menu screen'
                            }
                        }
                    },
                    center: {
                        stack: {
                            id: 'mainStack',
                            children: [
                                {
                                    stack: {
                                        id: 'tab1Stack',
                                        children: [
                                            {
                                                component: {
                                                    name: 'app.Component'
                                                }
                                            }
                                        ],
                                        options: {
                                            topBar: {
                                                background: {
                                                    color: '#50A7C2',
                                                },
                                                title: {
                                                    text: 'Namaz Timing',
                                                    fontSize: 20,
                                                    //color: 'white',
                                                    fontFamily: 'Ubuntu',
                                                    alignment: 'left'
                                                },
                                                leftButtons: [
                                                    {
                                                        id: 'buttonOne',
                                                        icon: sources[0]
                                                    }
                                                ],
                                                rightButtons: [
                                                  {
                                                    id: 'buttonTwo',
                                                    icon: sources[1]
                                                  }
                                                ]
                                            }
                                        }
                                    }
                                },
                            ],
                            options: {
                                  topBar: {
                                      background: {
                                        color: '#50A7C2',
                                      }
                                  },
                            }
                        }
                    }
                }
            }
        });
    });
});

这是我要使用它的功能

import qs from 'qs';
import { AsyncStorage } from 'react-native';
export async function addMasjid(Name, Address, email, Timing1, Timing2, Timing3, Timing4, Timing5, Timing6, Timing7) {
    const Data = await AsyncStorage.getItem('tokenData');
    parsed = JSON.parse(Data)
    var token = parsed.access_token;
    return fetch(`URL`, {
        method: 'POST',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/x-www-form-urlencoded',
        },
        body: qs.stringify({
            'name': Name,
            'address': Address,
            'email': email,
            'time_': Timing,
            'time_': Timing,
            'time_': Timing,
            'time_': Timing,
            'time_': Timing,
            'time_': Timing,
            'time_': Timing,
        })
    })
        .then(res => res.json())
        .catch(err => console.log(err))

在您的app.js中导入闪存消息组件并在底部调用。

app.js

import React from "react";
import { View } from "react-native";
import FlashMessage from "react-native-flash-message";
export default class App extends React.Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        // your entire code
        <FlashMessage position="top" />  <--- at the bottom
      </View>
    );
  }
}

现在,在您想使用的文件中。

import { showMessage, hideMessage } from "react-native-flash-message";

然后,只需在您想要的功能中使用showmessage即可。示例:

const someFunc = () => {
   showMessage({
      message : 'some message',
      type: 'success'
      ... other attributes
   })
}

相关内容

  • 没有找到相关文章

最新更新