I have a simple web view setup within react-native
I have nav bar at the bottom and the links open different screens with web views, however the pages save state. SO let's say I navigate to an internal page on the website (so like the about page of the website) when I go onto another screen and come back to the screen - the url state is saved. How can I make it so when I click on the nav button it always redirects to me to the initial page loaded in the web view...I've committed links etc as its sensitive data.
USE CASE:
User opens app, is greeted with a homepage - they can click links on the homepage which takes them to another part of the web page - if they navigate away from the Home Screen (within the app) then go back to the Home Screen on the app - the web view is on the last internal page they were on.
I want it so when they press the home button on the nabber on the app it effectively resets the web view?
Thanks
Code below:
const url = "websitelinkere.com/pageLink.html";
...
<View style={{ flex: 1 }}>
<WebView
javaScriptEnabled={true}
domStorageEnabled={true}
mixedContentMode={'compatibility'}
source={{
//meta type & http header locking for aded security
uri: url, //<-- I want it to always load pageLink.html <-- even if I've navigated to pageLinkDifferent.html
}}
onMessage={(event) => {}}
/>
</View>
Navbar (example link):
<View style={homePage.column}>
<TouchableOpacity onPress={() => navigation.navigate('JournalHome')}>
<Image style={homePage.navImage} source={journalHomeImage}/>
</TouchableOpacity>
</View>
I've tried researching the issue on stack overflow and online but haven't found a solution that works for me
you can use useFocusEffect in react-navigation
const INITIAL_URL = "websitelinkere.com/pageLink.html";
...
const webviewRef = useRef();
const [url,setUrl] = useState(INITIAL_URL)
...
useFocusEffect(
React.useCallback(() => {
if(webviewRef.current) {
setUrl(INITIAL_URL);
webviewRef.current.reload();
}
}, [])
);
...
<Webview
ref={webviewRef}
source={{ uri }}
/>
Related
I am using touchable opacity for my home page button, all menus are working perfectly but are not working correctly in two scenarios.
While launching the share popup and moving to another application
Open the play store for rating.
The problem I am facing
While pressing the button, the opacity and all actions work properly, but after coming back to the application, still, the touchable opacity is active.
<TouchableOpacity onPress={()=> shareApp() }>
<View>
<Image source={require('../Assets/Home_page/share.png')}/>
</View>
<View>
<Text>Share my app</Text>
</View>
</TouchableOpacity>
shareApp = () => {
var link="https://play.google.com/store/apps/details?id="+_packageid;
const result = await Share.share({
title: 'App link',
message:'Best app \n'+link,
url:link
});
}
See the above image, after returning to the application, still, the opacity is active. The same happened if the following code is executed.
Linking.openURL(link)
I am trying to refresh/ reload the page with an updated document once I click on a button. saveAnnotations(); saves the changes made to the document on the device and also updates the document with any other updates from other devices in the database.
The filepath is a REST URL to get the document.
After I click the sync button, the edits made to the document are saved but I want to reload the page so that it pulls the latest updated document from the database in the onclick button itself.
When I go back and return on this page I am able to see the lastest changes made but I want the document to reload when I click on sync button.
I tried using window.location.reload(false); but it closes the page where as I just want to reload the page or rerender filepath props to pull latest changes when I click on the sync button.
Any suggestions on how do I achieve that?
here's my code snippet
reRender = () => {
// calling the forceUpdate() method
this.forceUpdate();
window.location.reload(false);
};
render() {
return (
<View style={{ flex: 1 }}>
<DocumentView
document={filepath}
/>
<View style={styles.button}>
<Button
onPress={() => {
// Save Document
this.saveAnnotations();
}}
title="Sync"
/>
</View>
</View>
</View>
);
}
To achieve what you are looking for, you need to trigger the render method. Doing this will show the updated document. Here is a diagram showing the lifecycle methods of React components. As you can see, there are three ways to trigger the render method:
The component receives new props
Calling setState
Calling forceUpdate
For your use case, I would suggest adding a call to forceUpdate, like so:
<View style={styles.button}>
<Button
onPress={() => {
// Save Document
this.saveAnnotations();
this.forceUpdate(); // <-- add this
}}
title="Sync"
/>
</View>
I'm trying to use aws-amplify authenticatorfor my app. My idea is to show the app first (that's the reason why i didn't wrap the whole app into withAuthenticator) and if user needs to sign in they will be led to a authentication screen, which is like below:
import { Authenticator } from 'aws-amplify-react-native'
const AuthScreen =({ route }) => {
return (
<View style={{flex: 1}}>
<Authenticator>
<TouchableOpacity
onPress={() => {
navigation.goBack()
}}
>
<Text style={{fontSize: 25}}>go back</Text>
</TouchableOpacity>
</Authenticator>
</View>
)
}
export default AuthScreen;
however in this way once the user is signed in, the UI will display like below, with a string and a signout button:
picture
My question is how can i hide this string and display the info i want after user is signed in? i tried to make a CustomSignOut component, add it in but it didn't work (didn't override):
<CustomSignOut override={'SignIn'}/>
ok finally finally figured this out... use hideDefault={true} in , then add all the other components except for Greetings (includes signout button) and TOTPSetup (somehow it just didn't work when adding it on), and the signout button & the string will disappear
If I pass the amp url to react native webView, it shows a page that asks to the user, whether to redirect to amp page or not.
I want to show the amp page on web view without redirection, but how can I do that?
This is the webview component I use.
https://github.com/react-native-community/react-native-webview
<WebView
useWebkit
startInLoadingState
renderLoading={() => (
<View style={styles.spinnerContainer}>
<Spinner color={commonColor.lightBlue} />
</View>
)}
renderError={() => (
<NetworkError
refetch={() => {
WebViewRef && WebViewRef.reload();
}}
/>
)}
allowsBackForwardNavigationGestures
source={{ uri: url }}
/>
so here source uri, if I put the amp page url such as
https://www.google.co.jp/amp/s/www.traicy.com/20190127-ktrdia%3famp=1
it shows a page that asks whether or not redirect to the amp page. If you click yes, it shows the amp page though.
I use React-native and Expo for my mobile client.
Flow:
User taps to open up a modal from root view
Modal has Expo's Share and WebView invoking buttons.
When user taps to open either of them, nothing happens.
When the modal is closed manually by the user, then the WebBrowser/Share are suddenly invoked, and opened on the root view that the modal is a child of.
Both functions to call the Share and WebBrowser invokers are in the modal's controller.
Partial Content of the modal controller:
openBrowser = (url) => {
WebBrowser.openBrowserAsync(url);
}
shareModel = (url) => {
Share.share({
url: url
}) .then(console.log(`Shared ${url}`))
.catch(err => console.log(err))
}
render() {
return (
<Modal
visible={this.props.visible}
animationType={'slide'}
onRequestClose={this.props.onRequestClose}
>
<View style={styles.modalContainer}>
<View style={styles.oneButton}>
<TouchableOpacity style={styles.toolbarButton} onPress={() => this.openBrowser(this.props.model.public_url)}>
<SimpleLineIcons
name='globe'
size={29}
style={{ marginTop: 1 }}
color='#7366E3'
/>
<Text style={{ color: '#7366E3', fontSize: 13, marginTop: 1 }}>View</Text>
</TouchableOpacity>
</View>
</View>
</Modal>
)
}
Any ideas? This exact code worked well in the past and something changed.
It could be due to the new Expo client's SDK26. One of their breaking changes include methods in the WebBrowser, see https://blog.expo.io/expo-sdk-v26-0-0-is-now-available-2be6d9805b31