Skip to content

Commit

Permalink
Added beta support for Android 12. Closes #175.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbhanson committed Jun 9, 2021
1 parent cc2ad32 commit d4b5f98
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [1.2.0] - (2021-Jun-09)

* Added beta support for Android 12. Closes [#175](https://github.com/jonbhanson/flutter_native_splash/issues/175).

## [1.1.9] - (2021-Jun-09)

* Added path argument to command line. Thanks [@lyledean1](https://github.com/lyledean1) for PR [#180](https://github.com/jonbhanson/flutter_native_splash/pull/180).
Expand Down
18 changes: 17 additions & 1 deletion README.md
Expand Up @@ -17,7 +17,7 @@ First, add `flutter_native_splash` as a dev dependency in your pubspec.yaml file

```yaml
dev_dependencies:
flutter_native_splash: ^1.1.9
flutter_native_splash: ^1.2.0
```

Don't forget to `flutter pub get`.
Expand Down Expand Up @@ -100,6 +100,9 @@ flutter_native_splash:
#info_plist_files:
# - 'ios/Runner/Info-Debug.plist'
# - 'ios/Runner/Info-Release.plist'

# To enable support for Android 12, set the following parameter to true. Defaults to false.
#android12: true
```

## 2. Run the package
Expand All @@ -117,6 +120,19 @@ To specify the yaml file location just add --path with the command in the termin
flutter pub run flutter_native_splash:create --path=path/to/my/file.yaml
```

# Android 12 beta support

Android 12 has a [new method](https://developer.android.com/about/versions/12/features/splash-screen) of adding splash screens, which consists of specifying the window background, animated app icon, and the icon background. Android 12 also supports legacy splash screens as they have been implemented in Flutter and this package. At this time, this package will provide beta support for Android 12 with a legacy implementation.

To enable Android 12 support, [set up the Android 12 SDK](https://developer.android.com/about/versions/12/setup-sdk), add `android12: true` to your configuration, and run the package:

```
flutter pub run flutter_native_splash:create
```
The package will add a `styles.xml` in `values-v31` and `values-night-v31` resource folders, which will allow Android 12 to maintain the legacy splash screen.

This package will add support for the new Android 12 splash screens in the future. However, I will wait to see how Flutter adapts to the new splash screen format so that this package can complement Flutter's implementation and avoid reinventing the wheel.

# Recommendations
## Secondary splash screen:
The native splash screen is displayed while the native app loads the Flutter framework. Once Flutter loads, there may still be resources that need to be loaded before your app is ready. For this reason, you should consider implementing a Flutter splash screen that is displayed while these resources load. Here is a code example of a secondary Flutter splash screen, or use a package from [pub.dev](https://pub.dev).
Expand Down
17 changes: 17 additions & 0 deletions lib/android.dart
Expand Up @@ -40,6 +40,7 @@ void _createAndroidSplash({
required bool fullscreen,
required String backgroundImage,
required String darkBackgroundImage,
required bool android12,
}) {
if (imagePath.isNotEmpty) {
_applyImageAndroid(imagePath: imagePath);
Expand Down Expand Up @@ -97,6 +98,22 @@ void _createAndroidSplash({
}
}

if (android12) {
_applyStylesXml(
fullScreen: fullscreen,
file: _androidV31StylesFile,
template: _androidV31StylesXml);
_applyStylesXml(
fullScreen: fullscreen,
file: _androidV31NightStylesFile,
template: _androidV31StylesNightXml);
} else {
var file = File(_androidV31StylesFile);
if (file.existsSync()) file.deleteSync();
file = File(_androidV31StylesNightXml);
if (file.existsSync()) file.deleteSync();
}

_applyStylesXml(
fullScreen: fullscreen,
file: _androidStylesFile,
Expand Down
4 changes: 4 additions & 0 deletions lib/constants.dart
Expand Up @@ -12,6 +12,10 @@ const String _androidLaunchDarkBackgroundFile =
const String _androidStylesFile = _androidResFolder + 'values/styles.xml';
const String _androidNightStylesFile =
_androidResFolder + 'values-night/styles.xml';
const String _androidV31StylesFile =
_androidResFolder + 'values-v31/styles.xml';
const String _androidV31NightStylesFile =
_androidResFolder + 'values-night-v31/styles.xml';
const String _androidV21DrawableFolder = _androidResFolder + 'drawable-v21/';
const String _androidV21LaunchBackgroundFile =
_androidV21DrawableFolder + 'launch_background.xml';
Expand Down
2 changes: 2 additions & 0 deletions lib/flutter_native_splash.dart
Expand Up @@ -38,6 +38,7 @@ void createSplashByConfig(Map<String, dynamic> config) {
bool fullscreen = config['fullscreen'] ?? false;
String iosContentMode = config['ios_content_mode'] ?? 'center';
final webImageMode = (config['web_image_mode'] ?? 'center');
bool android12 = (config['android12'] ?? false);

if (!config.containsKey('android') || config['android']) {
_createAndroidSplash(
Expand All @@ -49,6 +50,7 @@ void createSplashByConfig(Map<String, dynamic> config) {
darkColor: darkColor,
gravity: gravity,
fullscreen: fullscreen,
android12: android12,
);
}

Expand Down
38 changes: 38 additions & 0 deletions lib/templates.dart
Expand Up @@ -59,6 +59,44 @@ const String _androidStylesNightXml = '''
</resources>
''';

const String _androidV31StylesXml = '''
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowSplashScreenBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
''';

const String _androidV31StylesNightXml = '''
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowSplashScreenBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
''';

// iOS-related templates
const String _iOSLaunchScreenStoryboardContent = '''
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: flutter_native_splash
description: Generates native code to customize Flutter's default white native splash screen with background color and splash image. Supports dark mode, full screen, and more.
version: 1.1.9
version: 1.2.0
homepage: https://github.com/jonbhanson/flutter_native_splash

environment:
Expand Down

0 comments on commit d4b5f98

Please sign in to comment.