Skip to content

Instantly share code, notes, and snippets.

@pratheeshrussell
Last active March 2, 2020 09:14
Show Gist options
  • Save pratheeshrussell/f382e9e582e1b41e4ce00a170db1ee71 to your computer and use it in GitHub Desktop.
Save pratheeshrussell/f382e9e582e1b41e4ce00a170db1ee71 to your computer and use it in GitHub Desktop.
native animated splash screen Splash Screen
//android\app\src\main\java\com\example\native_splash\CustomSplashScreen.java
//package name will differ based on projects
package com.example.native_splash;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.embedding.android.SplashScreen;
public class CustomSplashScreen implements SplashScreen {
private CustomSplashScreenView splashView;
@Nullable
public View createSplashView(@NonNull Context context, @Nullable Bundle bundle) {
if (splashView == null) {
splashView = new CustomSplashScreenView(context);
splashView.restoreSplashState(bundle);
}
return splashView;
}
//closing the splash
public void transitionToFlutter(Runnable onTransitionComplete) {
if (splashView != null) {
splashView.animateAway(onTransitionComplete);
}
else {
onTransitionComplete.run();
}
}
//state saving
@Override
public boolean doesSplashViewRememberItsTransition() {
return true;
}
@Override
@Nullable
public Bundle saveSplashScreenState() {
if (splashView != null) {
return splashView.saveSplashState();
} else {
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment