I sent the old code…below the current one that already exists onMessage
import React, { Component, useEffect, useState, useRef } from "react";
import {Platform, Dimensions, SafeAreaView, View, Image, Alert} from "react-native";
import { WebView } from "react-native-webview";
import Constants from "expo-constants";
import NetInfo from "@react-native-community/netinfo";
import { Audio } from 'expo-av';
import * as Notifications from 'expo-notifications';
export * from "expo-notifications";
import { Camera } from "expo-camera";
const BACKGROUND_COLOR = "#000000";
const DEVICE_WIDTH = Dimensions.get("window").width;
const DEVICE_HEIGHT = Dimensions.get("window").height;
const ANDROID_BAR_HEIGHT = Platform.OS === "android" ? Constants.statusBarHeight : 0;
const sound = new Audio.Sound();
/*
///// Notification
Notifications.requestPermissionsAsync()
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: false,
shouldSetBadge: false,
}),
});
*/
///// Sound intro
try {
const {
sound: soundObject,
status,
} = Audio.Sound.createAsync(require('./assets/open.mp3'), { shouldPlay: true });
// playing
} catch (error) {
// if error
}
///// Get permission of cam
Camera.requestPermissionsAsync();
export class message extends Component {
onMessage( event ) {
Alert.alert(
'On Message',
event.nativeEvent.data,
[
{text: 'OK'},
],
{ cancelable: true }
)
}
}
export default function App(props) {
const WEBVIEW = useRef()
const [loading, setLoading] = useState(true)
const [backButtonEnabled, setBackButtonEnabled] = useState(false)
const [isConnected, setConnected] = useState(true)
/*
Notifications.scheduleNotificationAsync({
content: {
title: "GoMexico 📬",
body: 'Nova mensagem',
data: { data: 'goes here' },
},
trigger: { seconds: 1 },
});
*/
// Webview content loadeds
function webViewLoaded() {
setLoading(false)
};
// Webview navigation state change
function onNavigationStateChange(navState) {
setBackButtonEnabled(navState.canGoBack)
};
useEffect(() => {
// Subscribe for net state
const netInfroSubscribe = NetInfo.addEventListener((state) => {
setConnected(state.isConnected)
if (!state.isConnected) {
alert("Sem ConexĂŁo");
}
});
// Clean up
return netInfroSubscribe
}, [])
return (
<SafeAreaView
style={{
flex: 1,
backgroundColor: BACKGROUND_COLOR,
}}
>
<View
style={{
height: ANDROID_BAR_HEIGHT,
backgroundColor: BACKGROUND_COLOR,
}}
></View>
{(loading || !isConnected) && (
<View
style={{
backgroundColor: BACKGROUND_COLOR,
position: "absolute",
top: 0,
left: 0,
zIndex: 10,
width: DEVICE_WIDTH,
height: DEVICE_HEIGHT + ANDROID_BAR_HEIGHT,
flex: 1,
alignItems: "center",
justifyContent: "center",
}}
>
<Image source={require("./assets/icon.png")}></Image>
</View>
)}
{isConnected && (
<WebView
originWhitelist={['*']}
allowsInlineMediaPlayback
javaScriptEnabled
scalesPageToFit
mediaPlaybackRequiresUserAction={false}
startInLoadingState
javaScriptEnabledAndroid
useWebkit
onLoad={webViewLoaded}
ref={WEBVIEW}
onMessage={this.onMessage}
useWebKit={true}
onNavigationStateChange={onNavigationStateChange}
source={{ uri: "https://socialranking.bubbleapps.io/version-test/" }}
/>
)}
</SafeAreaView>
);
}