Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29429

Show splash screen in ReactNative Java App for android

$
0
0

I am new to Android world. I have main-activity with three Framelayout.

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/react_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>

    <FrameLayout
        android:id="@+id/footer_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/loadingScreen_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ic_loading">

        <ProgressBar
            android:id="@+id/loading_spinner"
            style="?android:progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:progressDrawable="@drawable/spinner"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center"
            android:layout_marginBottom="100dp" />

    </FrameLayout>

</merge>

I am using loadingScreen_fragment_container to show the splash screen. I am loading the ReactNative app inside the Android app. Since Android activity is gets called first so i am showing the splash screen from there (Please correct me if this is incorrect.) so that user will not see white blank screen.

So loadingScreen_fragment_container occupies the whole screen with BG image and spinner. Meanwhile everything is loading behind. I am using NativeModules to call Java function from ReacteNative Js code once My app gets its data from service call. JavaFunction Simply hides the loadingScreen_fragment_container FrameLayout.

@ReactMethod    
public void HideSplashScreen(){
            Fragment splashScreenFragment = fragmentManager.findFragmentById(R.id.loadingScreen_fragment_container);
            if(splashScreenFragment != null && !splashScreenFragment.isHidden()) {
                fragmentManager.beginTransaction().hide(splashScreenFragment).commit();
                fragmentManager.beginTransaction().show(fragmentManager.findFragmentById(R.id.react_fragment_container)).commit();
            }
        }

Somehow this is not working for me, I can only see BG image and progress-bar. So I have few questions here

  1. Why Showing different fragment is not working for my case
  2. Is this a correct way to show the splash screen, as i am waiting for data to available to hide the splashscreen and callback is coming from react native layer.
  3. Since reactnative app is inside the Java app, so showing the splash screen in Java activity make more sense then in RN layer to avoid showing empty white screen
  4. Can any one point me any good document/blog for Reactive native threading model with Java app.

Thanks in advance


Viewing all articles
Browse latest Browse all 29429

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>