Reputation: 11
Hi I'm new to react native and am currently trying to add a flash message to the top of my mobile application upon the press of a button. I've read the https://www.npmjs.com/package/react-native-flash-message tutorial and watched a couple youtube videos on how to integrate it, but I can't seem to figure out how to integrate it into my code beyond guessing and checking which has taken up a lot of time. Part of my code from two pages is shown below, the app still functions and brings me to the home screen but does not show the flash message when I press the button. If you know how to do this or have any suggestions it would be greatly appreciated.
From App.js:
export default function App(){
return (
<View>
<FlashMessage position="top" />
</View>
);
};
From CreatEventScreen.js:
following code is within: function CreateEventScreen(props) {
{/* Create Event Button */}
<View style={styles.loginButton}>
<TouchableOpacity
style={styles.buttonTouchableOpacity}
onPress={() => {
showMessage({
message: "Success",
description: "The Event has been created",
type: "success",
});
Actions.HomeScreen()
}}>
<Text style={styles.btnTextWhite}>Create Event</Text>
</TouchableOpacity>
</View>
Upvotes: 1
Views: 5858
Reputation: 11
so your app.js file should look like this:
import CreateEventScreen from './CreatEventScreen.js' //Type the directory where your file is located.
import FlashMessage from "react-native-flash-message"
export default function App() {
return (
<>
<CreateEventScreen />
<FlashMessage position={"top"} />
</>
)
}
so your createEventScreen.js file should look like this:
import { showMessage } from "react-native-flash-message"
{/* Create Event Button */}
<View style={styles.loginButton}>
<TouchableOpacity
style={styles.buttonTouchableOpacity}
onPress={() => {
showMessage({
message: "Success",
description: "The Event has been created",
type: "success",
});
Actions.HomeScreen()
}}>
<Text style={styles.btnTextWhite}>Create Event</Text>
</TouchableOpacity>
</View>
Upvotes: 1