diff --git a/README.md b/README.md index 6e74765..7fec351 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,9 @@ flutter_native_splash: # To position the branding image at the bottom of the screen you can use bottom, bottomRight, # and bottomLeft. The default values is bottom if not specified or specified something else. #branding_mode: bottom + + # Set the branding padding from the bottom of the screen. The default value is 0 + # branding_bottom_padding: 24 # The color_dark, background_image_dark, image_dark, branding_dark are parameters that set the background # and image when the device is in dark mode. If they are not specified, the app will use the @@ -130,8 +133,10 @@ flutter_native_splash: #background_image_web: "assets/background-web.png" #background_image_dark_web: "assets/dark-background-web.png" #branding_android: assets/brand-android.png + #branding_bottom_padding_android: 24 #branding_dark_android: assets/dart_dark-android.png #branding_ios: assets/brand-ios.png + #branding_bottom_padding_ios: 24 #branding_dark_ios: assets/dart_dark-ios.png #branding_web: assets/brand-web.gif #branding_dark_web: assets/dart_dark-web.gif @@ -289,6 +294,7 @@ flutter_native_splash: color: "#ffffff" image: assets/logo-acceptance.png branding: assets/branding-acceptance.png + branding_bottom_padding: 24 color_dark: "#121212" image_dark: assets/logo-acceptance.png branding_dark: assets/branding-acceptance.png @@ -306,6 +312,7 @@ flutter_native_splash: color: "#ffffff" image: assets/logo-production.png branding: assets/branding-production.png + branding_bottom_padding: 24 color_dark: "#121212" image_dark: assets/logo-production.png branding_dark: assets/branding-production.png diff --git a/lib/android.dart b/lib/android.dart index ad47078..bd10441 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -56,6 +56,7 @@ void _createAndroidSplash({ required String? android12BackgroundColor, required String? android12DarkBackgroundColor, required String? brandingImagePath, + required String? brandingBottomPadding, required String? brandingDarkImagePath, required String? color, required String? darkColor, @@ -138,6 +139,7 @@ void _createAndroidSplash({ showImage: imagePath != null, showBranding: brandingImagePath != null, brandingGravity: brandingGravity, + brandingBottomPadding: brandingBottomPadding, ); if (darkColor != null || darkBackgroundImage != null) { @@ -147,6 +149,7 @@ void _createAndroidSplash({ showImage: imagePath != null, showBranding: brandingImagePath != null, brandingGravity: brandingGravity, + brandingBottomPadding: brandingBottomPadding, ); } @@ -157,6 +160,7 @@ void _createAndroidSplash({ showImage: imagePath != null, showBranding: brandingImagePath != null, brandingGravity: brandingGravity, + brandingBottomPadding: brandingBottomPadding, ); if (darkColor != null || darkBackgroundImage != null) { _applyLaunchBackgroundXml( @@ -166,6 +170,7 @@ void _createAndroidSplash({ showImage: imagePath != null, showBranding: brandingImagePath != null, brandingGravity: brandingGravity, + brandingBottomPadding: brandingBottomPadding, ); } } @@ -304,6 +309,7 @@ void _applyLaunchBackgroundXml({ required String gravity, required bool showImage, bool showBranding = false, + String? brandingBottomPadding, String brandingGravity = 'bottom', }) { String brandingGravityValue = brandingGravity; @@ -325,8 +331,11 @@ void _applyLaunchBackgroundXml({ if (showBranding && gravity != brandingGravityValue) { //add branding when splash image and branding image are not at the same position + final androidBrandingItemXml = _androidBrandingItemXml.replaceAll( + "{bottom_padding}", brandingBottomPadding ?? "0"); + print('[Android] branding bottom padding: ${brandingBottomPadding ?? "0"}'); final brandingItem = - XmlDocument.parse(_androidBrandingItemXml).rootElement.copy(); + XmlDocument.parse(androidBrandingItemXml).rootElement.copy(); if (brandingGravityValue == 'bottomRight') { brandingGravityValue = 'bottom|right'; } else if (brandingGravityValue == 'bottomLeft') { diff --git a/lib/cli_commands.dart b/lib/cli_commands.dart index 6d94cf7..49fcc6f 100644 --- a/lib/cli_commands.dart +++ b/lib/cli_commands.dart @@ -64,10 +64,16 @@ void _createSplashByConfig(Map config) { _checkImageExists(config: config, parameter: _Parameter.darkImageWeb); final String? brandingImage = _checkImageExists(config: config, parameter: _Parameter.brandingImage); + final String? brandingBottomPadding = + config[_Parameter.brandingBottomPadding]?.toString(); final String? brandingImageAndroid = _checkImageExists( config: config, parameter: _Parameter.brandingImageAndroid); + final String? brandingBottomPaddingAndroid = + config[_Parameter.brandingBottomPaddingAndroid]?.toString(); final String? brandingImageIos = _checkImageExists(config: config, parameter: _Parameter.brandingImageIos); + final String? brandingBottomPaddingIos = + config[_Parameter.brandingBottomPaddingIos]?.toString(); final String? brandingImageWeb = _checkImageExists(config: config, parameter: _Parameter.brandingImageWeb); final String? brandingDarkImage = _checkImageExists( @@ -155,6 +161,8 @@ void _createSplashByConfig(Map config) { imagePath: imageAndroid ?? image, darkImagePath: darkImageAndroid ?? darkImage, brandingImagePath: brandingImageAndroid ?? brandingImage, + brandingBottomPadding: + brandingBottomPaddingAndroid ?? brandingBottomPadding, brandingDarkImagePath: brandingDarkImageAndroid ?? brandingDarkImage, backgroundImage: backgroundImageAndroid ?? backgroundImage, darkBackgroundImage: darkBackgroundImageAndroid ?? darkBackgroundImage, @@ -189,6 +197,8 @@ void _createSplashByConfig(Map config) { darkBackgroundImage: darkBackgroundImageIos ?? darkBackgroundImage, brandingImagePath: brandingImageIos ?? brandingImage, brandingDarkImagePath: brandingDarkImageIos ?? brandingDarkImage, + brandingBottomPadding: + brandingBottomPaddingIos ?? brandingBottomPadding, color: colorIos ?? color, darkColor: darkColorIos ?? darkColor, plistFiles: plistFiles, @@ -420,8 +430,11 @@ class _Parameter { static const brandingDarkImageWeb = 'branding_dark_web'; static const brandingGravity = 'branding_mode'; static const brandingImage = 'branding'; + static const brandingBottomPadding = 'branding_bottom_padding'; static const brandingImageAndroid = 'branding_android'; + static const brandingBottomPaddingAndroid = 'branding_bottom_padding_android'; static const brandingImageIos = 'branding_ios'; + static const brandingBottomPaddingIos = 'branding_bottom_padding_ios'; static const brandingImageWeb = 'branding_web'; static const color = 'color'; static const colorAndroid = "color_android"; @@ -467,8 +480,11 @@ class _Parameter { brandingDarkImageWeb, brandingGravity, brandingImage, + brandingBottomPadding, brandingImageAndroid, brandingImageIos, + brandingBottomPaddingIos, + brandingBottomPaddingAndroid, brandingImageWeb, color, colorAndroid, diff --git a/lib/ios.dart b/lib/ios.dart index 2a12c0a..efb6277 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -55,6 +55,7 @@ void _createiOSSplash({ required String? imagePath, required String? darkImagePath, String? brandingImagePath, + String? brandingBottomPadding, String? brandingDarkImagePath, required String? color, required String? darkColor, @@ -141,6 +142,7 @@ void _createiOSSplash({ brandingImagePath: brandingImagePath, iosContentMode: iosContentMode, iosBrandingContentMode: iosBrandingContentMode, + brandingBottomPadding: brandingBottomPadding, ); _createBackground( colorString: color, @@ -209,6 +211,7 @@ void _updateLaunchScreenStoryboard({ required String? imagePath, required String iosContentMode, String? brandingImagePath, + String? brandingBottomPadding, String? iosBrandingContentMode, }) { String? iosBrandingContentModeValue = iosBrandingContentMode; @@ -376,7 +379,10 @@ void _updateLaunchScreenStoryboard({ } final element = view.getElement('constraints'); - final doc = XmlDocument.parse(toParse).rootElement.copy(); + final toParseBottomPadding = + toParse.replaceAll("{bottom_padding}", brandingBottomPadding ?? "0"); + print("[iOS] branding bottom padding: ${brandingBottomPadding ?? "0"}"); + final doc = XmlDocument.parse(toParseBottomPadding).rootElement.copy(); if (doc.firstChild != null) { print('[iOS] updating constraints with splash branding'); for (final v in doc.children) { @@ -396,6 +402,7 @@ void _createLaunchScreenStoryboard({ required String iosContentMode, required String? iosBrandingContentMode, required String? brandingImagePath, + required String? brandingBottomPadding, }) { final file = File(_flavorHelper.iOSLaunchScreenStoryboardFile); file.createSync(recursive: true); @@ -404,6 +411,7 @@ void _createLaunchScreenStoryboard({ return _updateLaunchScreenStoryboard( imagePath: imagePath, brandingImagePath: brandingImagePath, + brandingBottomPadding: brandingBottomPadding, iosContentMode: iosContentMode, iosBrandingContentMode: iosBrandingContentMode, ); diff --git a/lib/templates.dart b/lib/templates.dart index ce45978..0695a92 100644 --- a/lib/templates.dart +++ b/lib/templates.dart @@ -9,7 +9,7 @@ const String _androidLaunchItemXml = ''' '''; const String _androidBrandingItemXml = ''' - + '''; @@ -386,21 +386,21 @@ const String _iOSLaunchBackgroundConstraints = ''' const String _iOSBrandingCenterBottomConstraints = ''' - + '''; const String _iOSBrandingLeftBottomConstraints = ''' - + '''; const String _iOSBrandingRightBottomConstraints = ''' - + ''';