Skip to content

Instantly share code, notes, and snippets.

@diegolmello
Last active March 19, 2024 14:47
Show Gist options
  • Save diegolmello/4b64aa091f77e7c87eaca9a459b2f600 to your computer and use it in GitHub Desktop.
Save diegolmello/4b64aa091f77e7c87eaca9a459b2f600 to your computer and use it in GitHub Desktop.
Embedding Rocket.Chat on iframe in React Native
import React, {useRef} from 'react';
import {SafeAreaView} from 'react-native';
import WebView from 'react-native-webview';
function Page(): JSX.Element {
const webRef = useRef(null);
const login = () => {
setTimeout(() => {
if (webRef.current) {
webRef.current.injectJavaScript(
`window.postMessage({ externalCommand:'login-with-token', token: 'TOKEN_HERE' }); true;`,
);
}
}, 300);
};
return (
<SafeAreaView style={{flex: 1}}>
<WebView
ref={webRef}
source={{
uri: 'https://mobile.rocket.chat/channel/general?layout=embedded',
}}
style={{flex: 1}}
onLoadEnd={() => login()}
/>
</SafeAreaView>
);
}
export default Page;
@diegolmello
Copy link
Author

Simulator.Screen.Recording.-.iPhone.14.-.2023-04-05.at.17.44.30.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment