Skip to content

Commit

Permalink
Changed to normal View constructors for FlutterSplashView.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll committed Jul 2, 2019
1 parent 5925dfa commit 135df20
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
flutterView = new FlutterView(getActivity(), getRenderMode(), getTransparencyMode());
flutterView.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener);

flutterSplashView = new FlutterSplashView(getContext(), provideSplashScreen());
flutterSplashView = new FlutterSplashView(getContext());
flutterSplashView.setSplashScreen(provideSplashScreen());
flutterSplashView.setFlutterView(flutterView);

return flutterSplashView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import io.flutter.app.BuildConfig;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;

/**
* {@code View} that displays a {@link SplashScreen} until a given {@link FlutterView}
* renders its first frame.
*/
public class FlutterSplashView extends FrameLayout {
private static String TAG = "FlutterSplashView";

@Nullable
private final SplashScreen splashScreen;
private SplashScreen splashScreen;
@Nullable
private FlutterView flutterView;
@Nullable
Expand All @@ -43,12 +47,35 @@ public void run() {
}
};

public FlutterSplashView(
@NonNull Context context,
@Nullable SplashScreen splashScreen
) {
public FlutterSplashView(@NonNull Context context) {
super(context);
}

public FlutterSplashView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public FlutterSplashView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

/**
* Displays the given {@link SplashScreen} until Flutter renders its first frame.
* <p>
* The given {@link SplashScreen} is displayed as soon as this method is invoked, or
* upon attachment to the {@code Window}, whichever happens last.
* <p>
* If Flutter has already rendered its first frame, this method does not have any
* visual impact.
*/
public void setSplashScreen(@NonNull SplashScreen splashScreen) {
removeSplashScreen();

this.splashScreen = splashScreen;

if (isAttachedToWindow()) {
showSplashScreen();
}
}

/**
Expand Down

0 comments on commit 135df20

Please sign in to comment.