Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions platforms/android/lib/api/lib.api
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,21 @@ public final class com/shopify/checkoutkit/Configuration {
public final fun component3 ()Lcom/shopify/checkoutkit/Platform;
public final fun component4 ()Lcom/shopify/checkoutkit/LogLevel;
public final fun component5 ()Lcom/shopify/checkoutkit/Preloading;
public final fun component6 ()Ljava/lang/String;
public fun equals (Ljava/lang/Object;)Z
public final fun getAppearance ()Lcom/shopify/checkoutkit/CheckoutAppearance;
public final fun getLogLevel ()Lcom/shopify/checkoutkit/LogLevel;
public final fun getPlatform ()Lcom/shopify/checkoutkit/Platform;
public final fun getPreloading ()Lcom/shopify/checkoutkit/Preloading;
public final fun getSheet ()Lcom/shopify/checkoutkit/CheckoutSheetOptions;
public final fun getTitle ()Ljava/lang/String;
public fun hashCode ()I
public final fun setAppearance (Lcom/shopify/checkoutkit/CheckoutAppearance;)V
public final fun setLogLevel (Lcom/shopify/checkoutkit/LogLevel;)V
public final fun setPlatform (Lcom/shopify/checkoutkit/Platform;)V
public final fun setPreloading (Lcom/shopify/checkoutkit/Preloading;)V
public final fun setSheet (Lcom/shopify/checkoutkit/CheckoutSheetOptions;)V
public final fun setTitle (Ljava/lang/String;)V
public fun toString ()Ljava/lang/String;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private fun ComponentActivity.isTouchExplorationEnabled(): Boolean {

@Suppress("DEPRECATION")
private fun View.announceCheckoutTitleForAccessibility(activity: ComponentActivity) {
announceForAccessibility(activity.getString(R.string.checkout_web_view_title))
announceForAccessibility(ShopifyCheckoutKit.configuration.resolveCheckoutTitle(activity))
}

private const val LOG_TAG = "CheckoutBottomSheet"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.shopify.checkoutkit

import android.content.Context

/**
* Configuration for Shopify Checkout Kit.
*
Expand All @@ -12,8 +14,15 @@ public data class Configuration internal constructor(
var platform: Platform? = null,
var logLevel: LogLevel = LogLevel.WARN,
var preloading: Preloading = Preloading(),
var title: String? = null,
)

/**
* Resolves the checkout sheet header title, preferring a runtime-configured title over the localized default.
*/
internal fun Configuration.resolveCheckoutTitle(context: Context): String =
title ?: context.getString(R.string.checkout_web_view_title)

public data class Preloading(
public val enabled: Boolean = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public class ShopifyCheckout @MainThread internal constructor(
}

findViewById<TextView>(R.id.checkoutKitHeaderTitle).apply {
text = ShopifyCheckoutKit.configuration.resolveCheckoutTitle(context)
setTextColor(headerFontColor)
(layoutParams as? Toolbar.LayoutParams)?.let { params ->
params.topMargin = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CheckoutBottomSheetTest {
it.preloading = configuration.preloading
it.platform = configuration.platform
it.logLevel = configuration.logLevel
it.title = configuration.title
}
}

Expand Down Expand Up @@ -691,6 +692,37 @@ class CheckoutBottomSheetTest {
assertThat(titleLayoutParams.gravity and Gravity.CENTER).isEqualTo(Gravity.CENTER)
}

@Test
fun `uses default checkout title when none configured`() {
val sheet = presentBottomSheet()

val title = sheet.findViewById<TextView>(R.id.checkoutKitHeaderTitle)!!

assertThat(title.text).isEqualTo(activity.getString(R.string.checkout_web_view_title))
}

@Test
fun `applies custom title to header when configured`() {
ShopifyCheckoutKit.configure { it.title = "Custom Title" }

val sheet = presentBottomSheet()

val title = sheet.findViewById<TextView>(R.id.checkoutKitHeaderTitle)!!

assertThat(title.text).isEqualTo("Custom Title")
}

@Test
fun `resolveCheckoutTitle returns configured title or falls back to default string`() {
assertThat(ShopifyCheckoutKit.getConfiguration().resolveCheckoutTitle(activity))
.isEqualTo(activity.getString(R.string.checkout_web_view_title))

ShopifyCheckoutKit.configure { it.title = "Custom Title" }

assertThat(ShopifyCheckoutKit.getConfiguration().resolveCheckoutTitle(activity))
.isEqualTo("Custom Title")
}

@Test
fun `applies configured header title alignment and toolbar elevation`() {
ShopifyCheckoutKit.configuration.sheet = CheckoutSheetOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void tearDown() {
config.setPreloading(initialConfiguration.getPreloading());
config.setPlatform(initialConfiguration.getPlatform());
config.setLogLevel(initialConfiguration.getLogLevel());
config.setTitle(initialConfiguration.getTitle());
});
}

Expand Down Expand Up @@ -88,6 +89,17 @@ public void canCustomizeStorefrontAppearance() {
assertThat(appearance).isNotEqualTo(new CheckoutAppearance.Storefront());
}

@Test
public void canConfigureTitle() {
ShopifyCheckoutKit.configure(configuration -> {
configuration.setTitle("Java Title");
});

Configuration configuration = ShopifyCheckoutKit.getConfiguration();

assertThat(configuration.getTitle()).isEqualTo("Java Title");
}

@Test
public void canConfigurePreloading() {
ShopifyCheckoutKit.configure(configuration -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CheckoutKitAndroidDemo : Application() {
tapAwayToDismissEnabled = settings.tapAwayToDismissEnabled,
)
it.preloading = Preloading(enabled = settings.checkoutPreloadingEnabled)
it.title = "Plant Checkout"
}
}
}
Expand Down
Loading