What does a startup need? 6 steps on the way to success
7 minutes
Mobile
Dec 8, 2023
13 minutes
yarn add react-native-splash-screen
cd ios && pod install && cd ..
[super application:application didFinishLaunchingWithOptions:launchOptions];
[RNSplashScreen show]; // call our SplashScreen
return YES;
return [super application:application didFinishLaunchingWithOptions:launchOptions];
#import "RNSplashScreen.h"
<?xml version="1.0" encoding="utf-8"?>
<resources> <attr name="launchImage" format="reference"/>
</resources>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
....
</style>
<!-- Add this -->
<style name="LightTheme" parent="AppTheme">
<item name="launchImage">@drawable/launch_screen_light</item>
</style>
<!-- Add this -->
<style name="DarkTheme" parent="AppTheme">
<item name="launchImage">@drawable/launch_screen_dark</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="?attr/launchImage"
android:scaleType="centerCrop"
/>
</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
setTheme(R.style.DarkTheme);
break;
case Configuration.UI_MODE_NIGHT_NO:
setTheme(R.style.LightTheme);
break;
default:
setTheme(R.style.LightTheme);
}
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
import org.devio.rn.splashscreen.SplashScreen;
import android.content.res.Configuration;
public class MainActivity extends ReactActivity { …
import SplashScreen from 'react-native-splash-screen'
export default function App {
useEffect() {
// any asynchronous code can be here
// before opening the application
// hide our Splash Screen
SplashScreen.hide();
}
. . . render function
}