How to change native splash screen with Javascript splash screen? - react-native

I need that when the native splash screen finishes loading, another splash screen (now on the javascript side) continues loading... with the same image and the same size shown on the native splash screen.
I already tried to define some sizes and positions on screen. But they never look alike. Can anyone point me to some documentation for me to study or guide me on how I can do this?

Technically splash screen is a part of the native application. You can't modify it from React Native side.
However, using libraries like https://github.com/zoontek/react-native-bootsplash you can control when to hide the splash screen. For example:
const App = () => {
componentDidMount() {
// do your logic even async
RNBootSplash.hide(); // call it to hide native splash screen
}
}

Related

React-Native: Orientation.lockToLandscape() in componentWillUnmount takes time to work

I'm using webview to play a video on full screen in landscape mode in my react native app .on returning to previous page I want protrait mode back.(Ie :I only need landscape mode for video player page and portrait mode in rest of the pages)
code
componentWillUnmount(){
Orientation.lockToPortrait();
}
componentDidMount() {
Orientation.lockToLandscape();
}
This code works, but on navigating back the view remains in landscape mode for a short period of time. How can I get the view to rotate to portrait mode immediately on returning from video player page?

How to set go back function with ios back navigator in React Native?

I set deep link in my app.
So there is a website can open my app with schema.
I know user can just click the ios navigator to go back.
But I want to know is any way that I can put my button function in my app's screen just like the ios navigator ?
In componentDidMount set
BackHandler.addEventListener('hardwareBackPressCheckpointOverview', this.backPressed);
here this.backPressed is the function which contains your goback functionality.
then in componentWillUnmount you remove the event listener
BackHandler.removeEventListener('hardwareBackPressCheckpointOverview', this.backPressed);

React Native Linking to web page and push back button

I built a react-native app and if user clicks a link then app opens a default web browser and go to the link.
Linking.openURL(notification.link);
If user push back button from the android or ios devices, is there any way we can detect the back move?
You can add a listener for the same in react native.
There are total 4 listners for the same.
willFocus - the screen will focus
didFocus - the screen focused (if there was a transition, the transition completed)
willBlur - the screen will be unfocused
didBlur - the screen unfocused (if there was a transition, the transition completed)
Try the below code
componentWillMount(){
const didFocusSubscription = this.props.navigation.addListener(
'didFocus',
payload => {
console.warn('didFocus ', payload);
# just write your code/call a method here which you want to execute when the app comes from background
}
);
}
Dont forget to remove it when it is done.
componentWillUnmount(){
didFocusSubscription.remove();
}
More you can read here. Thanks :)

How to refresh a component which is already present in stack after navigating from another component in react native

Ex- I have two components A and B. I need to refresh component A after navigating from component B.
componentDid Mount doesn't work because A is already mounted.
How to achieve this. I am using react navigation to navigate from B->A
You can either use NavigationEvents from react-navigation or can pass a callback which will trigger on navigation.goBack().
Check this snack : Temporary Link
You can add a listener for the same in react native.
There are total 4 listners for the same.
willFocus - the screen will focus
didFocus - the screen focused (if there was a transition, the transition completed)
willBlur - the screen will be unfocused
didBlur - the screen unfocused (if there was a transition, the transition completed)
Try the below code
componentDidMount(){
const didFocusSubscription = this.props.navigation.addListener(
'didFocus',
payload => {
console.warn('didFocus ', payload);
# just write your code/call a method here which you want to execute when the app comes from a component
this.handleRefresh()
}
);
}
Dont forget to remove it when it is done.
componentWillMount(){
didFocusSubscription.remove();
}
More you can read here. Thanks :)

how to get a splash screen first and then go the main home screen when using react-native-navigation?

I am using react-native 0.32.0 and "react-native-navigation": "^1.0.30", And I want to get a splash screen first and then go to the main home screen, where I begin to use react-native-navigation. I googled a lot and did a lot re research but still do not know how to make this. I try to get the simplest config passed to Navigation.startSingleScreenApp, but I still get the navbar in iOS. is it possible to get a raw splash screen first and then use react-native-navigation for navigation?
I implemented this through navigation experimental itself. you can refer this repository on github for navigation experimental https://github.com/jlyman/RN-NavigationExperimental-Redux-Example
I used setTimeout() function in the constructor of the page which I am loading first through my navigation experimental. The page in which I used this function became the splash screen of my app. Here is the code.
class FirstScreen extends Component{
constructor(props) {
super(props);
setTimeout(this.props.OnChange, 3000); //Constructor of Splash Screen page
}
//render() code
}
and here is my onChange() function inside mapDispatchToProps() which is calling navigatePush() action creater of my navigation experimental
OnChange: () => {
dispatch(navigatePush('Login'))
}