Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support adjust padding bottom for branding image #709

Merged
merged 15 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,6 +139,7 @@ void _createAndroidSplash({
showImage: imagePath != null,
showBranding: brandingImagePath != null,
brandingGravity: brandingGravity,
brandingBottomPadding: brandingBottomPadding,
);

if (darkColor != null || darkBackgroundImage != null) {
Expand All @@ -147,6 +149,7 @@ void _createAndroidSplash({
showImage: imagePath != null,
showBranding: brandingImagePath != null,
brandingGravity: brandingGravity,
brandingBottomPadding: brandingBottomPadding,
);
}

Expand All @@ -157,6 +160,7 @@ void _createAndroidSplash({
showImage: imagePath != null,
showBranding: brandingImagePath != null,
brandingGravity: brandingGravity,
brandingBottomPadding: brandingBottomPadding,
);
if (darkColor != null || darkBackgroundImage != null) {
_applyLaunchBackgroundXml(
Expand All @@ -166,6 +170,7 @@ void _createAndroidSplash({
showImage: imagePath != null,
showBranding: brandingImagePath != null,
brandingGravity: brandingGravity,
brandingBottomPadding: brandingBottomPadding,
);
}
}
Expand Down Expand Up @@ -304,6 +309,7 @@ void _applyLaunchBackgroundXml({
required String gravity,
required bool showImage,
bool showBranding = false,
String? brandingBottomPadding,
String brandingGravity = 'bottom',
}) {
String brandingGravityValue = brandingGravity;
Expand All @@ -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 androidRandingItemXml = _androidBrandingItemXml.replaceAll(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

androidRandingItemXml is spelled wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the typo.
Please check again @jonbhanson

Thanks

"{bottom_padding}", brandingBottomPadding ?? "0");
print('[Android] branding bottom padding: ${brandingBottomPadding ?? "0"}');
final brandingItem =
XmlDocument.parse(_androidBrandingItemXml).rootElement.copy();
XmlDocument.parse(androidRandingItemXml).rootElement.copy();
if (brandingGravityValue == 'bottomRight') {
brandingGravityValue = 'bottom|right';
} else if (brandingGravityValue == 'bottomLeft') {
Expand Down
16 changes: 16 additions & 0 deletions lib/cli_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ void _createSplashByConfig(Map<String, dynamic> 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(
Expand Down Expand Up @@ -155,6 +161,8 @@ void _createSplashByConfig(Map<String, dynamic> config) {
imagePath: imageAndroid ?? image,
darkImagePath: darkImageAndroid ?? darkImage,
brandingImagePath: brandingImageAndroid ?? brandingImage,
brandingBottomPadding:
brandingBottomPaddingAndroid ?? brandingBottomPadding,
brandingDarkImagePath: brandingDarkImageAndroid ?? brandingDarkImage,
backgroundImage: backgroundImageAndroid ?? backgroundImage,
darkBackgroundImage: darkBackgroundImageAndroid ?? darkBackgroundImage,
Expand Down Expand Up @@ -189,6 +197,8 @@ void _createSplashByConfig(Map<String, dynamic> config) {
darkBackgroundImage: darkBackgroundImageIos ?? darkBackgroundImage,
brandingImagePath: brandingImageIos ?? brandingImage,
brandingDarkImagePath: brandingDarkImageIos ?? brandingDarkImage,
brandingBottomPadding:
brandingBottomPaddingIos ?? brandingBottomPadding,
color: colorIos ?? color,
darkColor: darkColorIos ?? darkColor,
plistFiles: plistFiles,
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -467,8 +480,11 @@ class _Parameter {
brandingDarkImageWeb,
brandingGravity,
brandingImage,
brandingBottomPadding,
brandingImageAndroid,
brandingImageIos,
brandingBottomPaddingIos,
brandingBottomPaddingAndroid,
brandingImageWeb,
color,
colorAndroid,
Expand Down
10 changes: 9 additions & 1 deletion lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void _createiOSSplash({
required String? imagePath,
required String? darkImagePath,
String? brandingImagePath,
String? brandingBottomPadding,
String? brandingDarkImagePath,
required String? color,
required String? darkColor,
Expand Down Expand Up @@ -141,6 +142,7 @@ void _createiOSSplash({
brandingImagePath: brandingImagePath,
iosContentMode: iosContentMode,
iosBrandingContentMode: iosBrandingContentMode,
brandingBottomPadding: brandingBottomPadding,
);
_createBackground(
colorString: color,
Expand Down Expand Up @@ -209,6 +211,7 @@ void _updateLaunchScreenStoryboard({
required String? imagePath,
required String iosContentMode,
String? brandingImagePath,
String? brandingBottomPadding,
String? iosBrandingContentMode,
}) {
String? iosBrandingContentModeValue = iosBrandingContentMode;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -404,6 +411,7 @@ void _createLaunchScreenStoryboard({
return _updateLaunchScreenStoryboard(
imagePath: imagePath,
brandingImagePath: brandingImagePath,
brandingBottomPadding: brandingBottomPadding,
iosContentMode: iosContentMode,
iosBrandingContentMode: iosBrandingContentMode,
);
Expand Down
8 changes: 4 additions & 4 deletions lib/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const String _androidLaunchItemXml = '''
''';

const String _androidBrandingItemXml = '''
<item>
<item android:bottom="{bottom_padding}dp">
<bitmap android:gravity="center" android:src="@drawable/branding" />
</item>
''';
Expand Down Expand Up @@ -386,21 +386,21 @@ const String _iOSLaunchBackgroundConstraints = '''
const String _iOSBrandingCenterBottomConstraints = '''
<constraints>
<constraint firstItem="Uyq-Kz-ftE" firstAttribute="centerX" secondItem="YRO-k0-Ey4" secondAttribute="centerX" id="3kg-TC-cPP"/>
<constraint firstAttribute="bottom" secondItem="Uyq-Kz-ftE" secondAttribute="bottom" id="8Yb-q4-8bl"/>
<constraint firstAttribute="bottom" secondItem="Uyq-Kz-ftE" secondAttribute="bottom" constant="{bottom_padding}" id="8Yb-q4-8bl"/>
</constraints>
''';

const String _iOSBrandingLeftBottomConstraints = '''
<constraints>
<constraint firstAttribute="leading" secondItem="Uyq-Kz-ftE" secondAttribute="leading" id="3kg-TC-cPP"/>
<constraint firstAttribute="bottom" secondItem="Uyq-Kz-ftE" secondAttribute="bottom" id="8Yb-q4-8bl"/>
<constraint firstAttribute="bottom" secondItem="Uyq-Kz-ftE" secondAttribute="bottom" constant="{bottom_padding}" id="8Yb-q4-8bl"/>
</constraints>
''';

const String _iOSBrandingRightBottomConstraints = '''
<constraints>
<constraint firstAttribute="trailing" secondItem="Uyq-Kz-ftE" secondAttribute="trailing" id="3kg-TC-cPP"/>
<constraint firstAttribute="bottom" secondItem="Uyq-Kz-ftE" secondAttribute="bottom" id="8Yb-q4-8lb"/>
<constraint firstAttribute="bottom" secondItem="Uyq-Kz-ftE" secondAttribute="bottom" constant="{bottom_padding}" id="8Yb-q4-8lb"/>
</constraints>
''';

Expand Down