@stripe/stripe-react-native 0.71.0 → 0.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementView.kt +7 -103
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementViewManager.kt +1 -5
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +0 -26
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +6 -21
- package/android/src/main/java/com/reactnativestripesdk/LinkControllerManager.kt +59 -18
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +14 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +6 -50
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +38 -187
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +2 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
- package/android/src/onramp/java/com/reactnativestripesdk/OnrampMappers.kt +1 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +0 -60
- package/ios/CurrencySelectorElementView.swift +18 -129
- package/ios/Mappers.swift +2 -0
- package/ios/PaymentMethodFactory.swift +14 -1
- package/ios/StripeSdk.mm +7 -0
- package/ios/StripeSdkImpl+Checkout.swift +35 -259
- package/ios/StripeSdkImpl+Embedded.swift +5 -28
- package/ios/StripeSdkImpl+LinkController.swift +40 -2
- package/ios/StripeSdkImpl+PaymentSheet.swift +2 -15
- package/ios/StripeSdkImpl.swift +2 -4
- package/lib/commonjs/connect/EmbeddedComponent.js +2 -2
- package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/hooks/useLinkController.js +1 -1
- package/lib/commonjs/hooks/useLinkController.js.map +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/module/connect/EmbeddedComponent.js +2 -2
- package/lib/module/connect/EmbeddedComponent.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/hooks/useLinkController.js +1 -1
- package/lib/module/hooks/useLinkController.js.map +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts +1 -0
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts +11 -0
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useLinkController.d.ts +7 -0
- package/lib/typescript/src/hooks/useLinkController.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +4 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/LinkController.d.ts +10 -5
- package/lib/typescript/src/types/LinkController.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts +9 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/connect/EmbeddedComponent.tsx +14 -2
- package/src/functions.ts +26 -0
- package/src/hooks/useLinkController.tsx +24 -1
- package/src/specs/NativeStripeSdkModule.ts +5 -0
- package/src/types/LinkController.ts +9 -5
- package/src/types/PaymentIntent.ts +11 -1
- package/stripe-react-native.podspec +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorAppearance.kt +0 -229
- package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutAddressUpdate.kt +0 -45
- package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutMappers.kt +0 -127
- package/android/src/test/java/com/reactnativestripesdk/CurrencySelectorAppearanceTest.kt +0 -137
- package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutMappersTest.kt +0 -98
- package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutTestFixtures.java +0 -57
- package/ios/CurrencySelectorAppearance.swift +0 -120
- package/ios/Mappers+Checkout.swift +0 -337
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
package com.reactnativestripesdk
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import androidx.test.core.app.ApplicationProvider
|
|
5
|
-
import com.reactnativestripesdk.utils.readableMapOf
|
|
6
|
-
import com.stripe.android.checkout.Checkout
|
|
7
|
-
import com.stripe.android.paymentelement.CheckoutSessionPreview
|
|
8
|
-
import org.junit.Assert.assertEquals
|
|
9
|
-
import org.junit.Assert.assertNotNull
|
|
10
|
-
import org.junit.Test
|
|
11
|
-
import org.junit.runner.RunWith
|
|
12
|
-
import org.robolectric.RobolectricTestRunner
|
|
13
|
-
|
|
14
|
-
@OptIn(CheckoutSessionPreview::class)
|
|
15
|
-
@RunWith(RobolectricTestRunner::class)
|
|
16
|
-
class CurrencySelectorAppearanceTest {
|
|
17
|
-
private val context: Context = ApplicationProvider.getApplicationContext()
|
|
18
|
-
|
|
19
|
-
@Test
|
|
20
|
-
fun buildCurrencySelectorAppearance_WithNullMap_ReturnsDefaultAppearance() {
|
|
21
|
-
val appearance = buildCurrencySelectorAppearance(null, context)
|
|
22
|
-
|
|
23
|
-
assertNotNull(appearance)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Test
|
|
27
|
-
fun buildCurrencySelectorAppearance_WithEmptyMap_ReturnsDefaultAppearance() {
|
|
28
|
-
val appearance = buildCurrencySelectorAppearance(readableMapOf(), context)
|
|
29
|
-
|
|
30
|
-
assertNotNull(appearance)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@Test
|
|
34
|
-
fun buildCurrencySelectorAppearance_WithColorStrings_Success() {
|
|
35
|
-
val appearance =
|
|
36
|
-
buildCurrencySelectorAppearance(
|
|
37
|
-
readableMapOf(
|
|
38
|
-
"background" to "#111111",
|
|
39
|
-
"selectedBackground" to "#222222",
|
|
40
|
-
"borderColor" to "#333333",
|
|
41
|
-
"textColor" to "#444444",
|
|
42
|
-
"selectedTextColor" to "#555555",
|
|
43
|
-
"textSecondaryColor" to "#666666",
|
|
44
|
-
"dangerColor" to "#777777",
|
|
45
|
-
),
|
|
46
|
-
context,
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
assertNotNull(getField(appearance, "background"))
|
|
50
|
-
assertNotNull(getField(appearance, "selectedBackground"))
|
|
51
|
-
assertNotNull(getField(appearance, "borderColor"))
|
|
52
|
-
assertNotNull(getField(appearance, "textColor"))
|
|
53
|
-
assertNotNull(getField(appearance, "selectedTextColor"))
|
|
54
|
-
assertNotNull(getField(appearance, "textSecondaryColor"))
|
|
55
|
-
assertNotNull(getField(appearance, "dangerColor"))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@Test
|
|
59
|
-
fun buildCurrencySelectorAppearance_WithThemedColor_UsesLightColor() {
|
|
60
|
-
val appearance =
|
|
61
|
-
buildCurrencySelectorAppearance(
|
|
62
|
-
readableMapOf(
|
|
63
|
-
"textColor" to
|
|
64
|
-
readableMapOf(
|
|
65
|
-
"light" to "#000000",
|
|
66
|
-
"dark" to "#FFFFFF",
|
|
67
|
-
),
|
|
68
|
-
),
|
|
69
|
-
context,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
assertNotNull(getField(appearance, "textColor"))
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Test
|
|
76
|
-
fun buildCurrencySelectorAppearance_WithInvalidColor_IgnoresValue() {
|
|
77
|
-
val appearance =
|
|
78
|
-
buildCurrencySelectorAppearance(
|
|
79
|
-
readableMapOf(
|
|
80
|
-
"textColor" to "#FF",
|
|
81
|
-
),
|
|
82
|
-
context,
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
// Invalid hex is silently ignored (logged as warning), color remains null/default
|
|
86
|
-
val field = appearance.javaClass.getDeclaredField("textColor")
|
|
87
|
-
field.isAccessible = true
|
|
88
|
-
val textColor = field.get(appearance)
|
|
89
|
-
assertEquals(null, textColor)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
@Test
|
|
93
|
-
fun buildCurrencySelectorAppearance_WithDimensionsAndFont_Success() {
|
|
94
|
-
val appearance =
|
|
95
|
-
buildCurrencySelectorAppearance(
|
|
96
|
-
readableMapOf(
|
|
97
|
-
"cornerRadius" to 12.0,
|
|
98
|
-
"borderWidth" to 2.0,
|
|
99
|
-
"contentVerticalPadding" to 6.0,
|
|
100
|
-
"font" to
|
|
101
|
-
readableMapOf(
|
|
102
|
-
"scale" to 1.2,
|
|
103
|
-
),
|
|
104
|
-
),
|
|
105
|
-
context,
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
assertEquals(12f, getField(appearance, "cornerRadiusDp"))
|
|
109
|
-
assertEquals(2f, getField(appearance, "borderWidthDp"))
|
|
110
|
-
assertEquals(6f, getField(appearance, "contentVerticalPaddingDp"))
|
|
111
|
-
assertEquals(1.2f, getField(appearance, "sizeScaleFactor"))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@Test
|
|
115
|
-
fun buildCurrencySelectorAppearance_WithLabelContentValues_Success() {
|
|
116
|
-
listOf("automatic", "currencyCode", "amount").forEach { labelContent ->
|
|
117
|
-
val appearance =
|
|
118
|
-
buildCurrencySelectorAppearance(
|
|
119
|
-
readableMapOf(
|
|
120
|
-
"labelContent" to labelContent,
|
|
121
|
-
),
|
|
122
|
-
context,
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
assertNotNull(getField(appearance, "labelContent"))
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private fun getField(
|
|
130
|
-
appearance: Checkout.CurrencySelectorContentAppearance,
|
|
131
|
-
fieldName: String,
|
|
132
|
-
): Any? {
|
|
133
|
-
val field = appearance.javaClass.getDeclaredField(fieldName)
|
|
134
|
-
field.isAccessible = true
|
|
135
|
-
return field.get(appearance)
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
package com.reactnativestripesdk.utils
|
|
2
|
-
|
|
3
|
-
import com.stripe.android.paymentelement.CheckoutSessionPreview
|
|
4
|
-
import org.junit.Assert.assertEquals
|
|
5
|
-
import org.junit.Assert.assertFalse
|
|
6
|
-
import org.junit.Assert.assertNotNull
|
|
7
|
-
import org.junit.Assert.assertNull
|
|
8
|
-
import org.junit.Test
|
|
9
|
-
import org.junit.runner.RunWith
|
|
10
|
-
import org.robolectric.RobolectricTestRunner
|
|
11
|
-
|
|
12
|
-
@RunWith(RobolectricTestRunner::class)
|
|
13
|
-
@OptIn(CheckoutSessionPreview::class)
|
|
14
|
-
class CheckoutMappersTest {
|
|
15
|
-
@Test
|
|
16
|
-
fun mapFromCheckoutState_mapsLoadedSession() {
|
|
17
|
-
val mapped =
|
|
18
|
-
mapFromCheckoutState(
|
|
19
|
-
isLoading = false,
|
|
20
|
-
session = CheckoutTestFixtures.fullSession(),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
assertEquals("loaded", mapped.getString("status"))
|
|
24
|
-
|
|
25
|
-
val session = mapped.getMap("session")
|
|
26
|
-
assertNotNull(session)
|
|
27
|
-
assertEquals("cs_test_123", session!!.getString("id"))
|
|
28
|
-
assertFalse(session.getBoolean("livemode"))
|
|
29
|
-
assertEquals("usd", session.getString("currency"))
|
|
30
|
-
|
|
31
|
-
val status = session.getMap("status")
|
|
32
|
-
assertNotNull(status)
|
|
33
|
-
assertEquals("open", status!!.getString("type"))
|
|
34
|
-
|
|
35
|
-
val tax = session.getMap("tax")
|
|
36
|
-
assertNotNull(tax)
|
|
37
|
-
assertEquals("ready", tax!!.getString("status"))
|
|
38
|
-
|
|
39
|
-
val total = session.getMap("total")
|
|
40
|
-
assertNotNull(total)
|
|
41
|
-
val subtotal = total!!.getMap("subtotal")
|
|
42
|
-
assertNotNull(subtotal)
|
|
43
|
-
assertEquals(5000.0, subtotal!!.getDouble("minorUnitsAmount"), 0.0)
|
|
44
|
-
assertEquals("", subtotal.getString("amount"))
|
|
45
|
-
|
|
46
|
-
val grandTotal = total.getMap("total")
|
|
47
|
-
assertNotNull(grandTotal)
|
|
48
|
-
assertEquals(4044.0, grandTotal!!.getDouble("minorUnitsAmount"), 0.0)
|
|
49
|
-
|
|
50
|
-
val lineItems = session.getArray("lineItems")
|
|
51
|
-
assertNotNull(lineItems)
|
|
52
|
-
assertEquals(2, lineItems!!.size())
|
|
53
|
-
assertEquals("li_item1", lineItems.getMap(0)?.getString("id"))
|
|
54
|
-
assertEquals("Llama Figure", lineItems.getMap(0)?.getString("name"))
|
|
55
|
-
assertEquals(2, lineItems.getMap(0)?.getInt("quantity"))
|
|
56
|
-
assertFalse(lineItems.getMap(0)!!.hasKey("unitAmount"))
|
|
57
|
-
|
|
58
|
-
val item2UnitAmount = lineItems.getMap(1)?.getMap("unitAmount")
|
|
59
|
-
assertNotNull(item2UnitAmount)
|
|
60
|
-
assertEquals(2499.0, item2UnitAmount!!.getDouble("minorUnitsAmount"), 0.0)
|
|
61
|
-
|
|
62
|
-
val shippingOptions = session.getArray("shippingOptions")
|
|
63
|
-
assertNotNull(shippingOptions)
|
|
64
|
-
assertEquals(2, shippingOptions!!.size())
|
|
65
|
-
assertEquals("shr_standard", shippingOptions.getMap(0)?.getString("id"))
|
|
66
|
-
val shippingAmount = shippingOptions.getMap(0)?.getMap("amount")
|
|
67
|
-
assertNotNull(shippingAmount)
|
|
68
|
-
assertEquals(500.0, shippingAmount!!.getDouble("minorUnitsAmount"), 0.0)
|
|
69
|
-
|
|
70
|
-
val discountAmounts = session.getArray("discountAmounts")
|
|
71
|
-
assertNotNull(discountAmounts)
|
|
72
|
-
assertEquals(0, discountAmounts!!.size())
|
|
73
|
-
|
|
74
|
-
val currencyOptions = session.getArray("currencyOptions")
|
|
75
|
-
assertNotNull(currencyOptions)
|
|
76
|
-
assertEquals(0, currencyOptions!!.size())
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@Test
|
|
80
|
-
fun mapFromCheckoutState_mapsLoadingStateAndOmitsBlankCurrency() {
|
|
81
|
-
val mapped =
|
|
82
|
-
mapFromCheckoutState(
|
|
83
|
-
isLoading = true,
|
|
84
|
-
session = CheckoutTestFixtures.blankCurrencySession(),
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
assertEquals("loading", mapped.getString("status"))
|
|
88
|
-
|
|
89
|
-
val session = mapped.getMap("session")
|
|
90
|
-
assertNotNull(session)
|
|
91
|
-
assertEquals("cs_test_blank_currency", session!!.getString("id"))
|
|
92
|
-
assertFalse(session.hasKey("currency"))
|
|
93
|
-
assertNull(session.getMap("total"))
|
|
94
|
-
assertEquals(0, session.getArray("lineItems")!!.size())
|
|
95
|
-
assertEquals(0, session.getArray("shippingOptions")!!.size())
|
|
96
|
-
assertEquals(0, session.getArray("discountAmounts")!!.size())
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
package com.reactnativestripesdk.utils;
|
|
2
|
-
|
|
3
|
-
import com.stripe.android.checkout.CheckoutSession;
|
|
4
|
-
import com.stripe.android.paymentsheet.verticalmode.CurrencySelectorOptions;
|
|
5
|
-
import java.util.Arrays;
|
|
6
|
-
import java.util.Collections;
|
|
7
|
-
|
|
8
|
-
public final class CheckoutTestFixtures {
|
|
9
|
-
private CheckoutTestFixtures() {}
|
|
10
|
-
|
|
11
|
-
public static CheckoutSession fullSession() {
|
|
12
|
-
CheckoutSession.TotalSummary totals =
|
|
13
|
-
new CheckoutSession.TotalSummary(
|
|
14
|
-
5000L,
|
|
15
|
-
4044L,
|
|
16
|
-
4044L,
|
|
17
|
-
Arrays.asList(
|
|
18
|
-
new CheckoutSession.DiscountAmount(500L, "SUMMER10"),
|
|
19
|
-
new CheckoutSession.DiscountAmount(250L, "LOYALTY5")),
|
|
20
|
-
Collections.singletonList(
|
|
21
|
-
new CheckoutSession.TaxAmount(294L, false, "Sales Tax", 6.875d)),
|
|
22
|
-
new CheckoutSession.ShippingRate(
|
|
23
|
-
"shr_standard", 500L, "Standard Shipping", "5-7 business days"),
|
|
24
|
-
null);
|
|
25
|
-
|
|
26
|
-
return new CheckoutSession(
|
|
27
|
-
"cs_test_123",
|
|
28
|
-
CheckoutSession.Status.Open,
|
|
29
|
-
false,
|
|
30
|
-
"usd",
|
|
31
|
-
null,
|
|
32
|
-
new CheckoutSession.Tax(CheckoutSession.Tax.Status.Ready),
|
|
33
|
-
totals,
|
|
34
|
-
Arrays.asList(
|
|
35
|
-
new CheckoutSession.LineItem("li_item1", "Llama Figure", 2, null, 1998L, 1998L),
|
|
36
|
-
new CheckoutSession.LineItem("li_item2", "Alpaca Plushie", 1, 2499L, 2499L, 2499L)),
|
|
37
|
-
Arrays.asList(
|
|
38
|
-
new CheckoutSession.ShippingRate("shr_standard", 500L, "Standard Shipping", null),
|
|
39
|
-
new CheckoutSession.ShippingRate(
|
|
40
|
-
"shr_express", 1500L, "Express Shipping", "1-2 business days")),
|
|
41
|
-
(CurrencySelectorOptions) null);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static CheckoutSession blankCurrencySession() {
|
|
45
|
-
return new CheckoutSession(
|
|
46
|
-
"cs_test_blank_currency",
|
|
47
|
-
CheckoutSession.Status.Open,
|
|
48
|
-
false,
|
|
49
|
-
"",
|
|
50
|
-
null,
|
|
51
|
-
new CheckoutSession.Tax(CheckoutSession.Tax.Status.Ready),
|
|
52
|
-
null,
|
|
53
|
-
Collections.<CheckoutSession.LineItem>emptyList(),
|
|
54
|
-
Collections.<CheckoutSession.ShippingRate>emptyList(),
|
|
55
|
-
(CurrencySelectorOptions) null);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// CurrencySelectorAppearance.swift
|
|
3
|
-
// stripe-react-native
|
|
4
|
-
//
|
|
5
|
-
// Created by Nick Porter on 6/24/26.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
@_spi(ReactNativeSDK) import StripePaymentSheet
|
|
9
|
-
import UIKit
|
|
10
|
-
|
|
11
|
-
internal class CurrencySelectorAppearance {
|
|
12
|
-
class func buildAppearanceFromParams(params: NSDictionary?) -> Checkout.CurrencySelectorView.Appearance {
|
|
13
|
-
var appearance = Checkout.CurrencySelectorView.Appearance()
|
|
14
|
-
|
|
15
|
-
guard let params = params else { return appearance }
|
|
16
|
-
|
|
17
|
-
if let background = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.BACKGROUND) {
|
|
18
|
-
appearance.background = background
|
|
19
|
-
}
|
|
20
|
-
if let selectedBackground = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.SELECTED_BACKGROUND) {
|
|
21
|
-
appearance.selectedBackground = selectedBackground
|
|
22
|
-
}
|
|
23
|
-
if let borderColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.BORDER_COLOR) {
|
|
24
|
-
appearance.border = borderColor
|
|
25
|
-
}
|
|
26
|
-
if let textColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.TEXT_COLOR) {
|
|
27
|
-
appearance.text = textColor
|
|
28
|
-
}
|
|
29
|
-
if let selectedTextColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.SELECTED_TEXT_COLOR) {
|
|
30
|
-
appearance.selectedText = selectedTextColor
|
|
31
|
-
}
|
|
32
|
-
if let textSecondaryColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.TEXT_SECONDARY_COLOR) {
|
|
33
|
-
appearance.textSecondary = textSecondaryColor
|
|
34
|
-
}
|
|
35
|
-
if let dangerColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.DANGER_COLOR) {
|
|
36
|
-
appearance.danger = dangerColor
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if let cornerRadius = params[CurrencySelectorAppearanceKeys.CORNER_RADIUS] as? CGFloat {
|
|
40
|
-
appearance.cornerRadius = cornerRadius
|
|
41
|
-
}
|
|
42
|
-
if let borderWidth = params[CurrencySelectorAppearanceKeys.BORDER_WIDTH] as? CGFloat {
|
|
43
|
-
appearance.borderWidth = borderWidth
|
|
44
|
-
}
|
|
45
|
-
if let contentVerticalPadding = params[CurrencySelectorAppearanceKeys.CONTENT_VERTICAL_PADDING] as? CGFloat {
|
|
46
|
-
appearance.contentVerticalPadding = contentVerticalPadding
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if let fontParams = params[CurrencySelectorAppearanceKeys.FONT] as? NSDictionary {
|
|
50
|
-
if let family = fontParams[CurrencySelectorAppearanceKeys.FAMILY] as? String,
|
|
51
|
-
let customFont = UIFont(name: family, size: appearance.font.pointSize) {
|
|
52
|
-
appearance.font = customFont
|
|
53
|
-
}
|
|
54
|
-
if let scale = fontParams[CurrencySelectorAppearanceKeys.SCALE] as? CGFloat {
|
|
55
|
-
appearance.sizeScaleFactor = scale
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if let labelContent = params[CurrencySelectorAppearanceKeys.LABEL_CONTENT] as? String {
|
|
60
|
-
switch labelContent {
|
|
61
|
-
case CurrencySelectorAppearanceKeys.CURRENCY_CODE:
|
|
62
|
-
appearance.labelContent = .currencyCode
|
|
63
|
-
case CurrencySelectorAppearanceKeys.AMOUNT:
|
|
64
|
-
appearance.labelContent = .amount
|
|
65
|
-
case CurrencySelectorAppearanceKeys.AUTOMATIC:
|
|
66
|
-
appearance.labelContent = .automatic
|
|
67
|
-
default:
|
|
68
|
-
break
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return appearance
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private class func parseThemedColor(params: NSDictionary, key: String) -> UIColor? {
|
|
76
|
-
if let colorDict = params[key] as? [String: String] {
|
|
77
|
-
let light = colorDict[CurrencySelectorAppearanceKeys.LIGHT]
|
|
78
|
-
let dark = colorDict[CurrencySelectorAppearanceKeys.DARK]
|
|
79
|
-
guard light != nil || dark != nil else { return nil }
|
|
80
|
-
return UIColor { traitCollection in
|
|
81
|
-
let hex = traitCollection.userInterfaceStyle == .dark
|
|
82
|
-
? (dark ?? light!)
|
|
83
|
-
: (light ?? dark!)
|
|
84
|
-
return UIColor(hexString: hex)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if let colorString = params[key] as? String {
|
|
89
|
-
return UIColor(hexString: colorString)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return nil
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private enum CurrencySelectorAppearanceKeys {
|
|
97
|
-
static let LIGHT = "light"
|
|
98
|
-
static let DARK = "dark"
|
|
99
|
-
|
|
100
|
-
static let BACKGROUND = "background"
|
|
101
|
-
static let SELECTED_BACKGROUND = "selectedBackground"
|
|
102
|
-
static let BORDER_COLOR = "borderColor"
|
|
103
|
-
static let TEXT_COLOR = "textColor"
|
|
104
|
-
static let SELECTED_TEXT_COLOR = "selectedTextColor"
|
|
105
|
-
static let TEXT_SECONDARY_COLOR = "textSecondaryColor"
|
|
106
|
-
static let DANGER_COLOR = "dangerColor"
|
|
107
|
-
|
|
108
|
-
static let CORNER_RADIUS = "cornerRadius"
|
|
109
|
-
static let BORDER_WIDTH = "borderWidth"
|
|
110
|
-
static let CONTENT_VERTICAL_PADDING = "contentVerticalPadding"
|
|
111
|
-
|
|
112
|
-
static let FONT = "font"
|
|
113
|
-
static let FAMILY = "family"
|
|
114
|
-
static let SCALE = "scale"
|
|
115
|
-
|
|
116
|
-
static let LABEL_CONTENT = "labelContent"
|
|
117
|
-
static let AUTOMATIC = "automatic"
|
|
118
|
-
static let CURRENCY_CODE = "currencyCode"
|
|
119
|
-
static let AMOUNT = "amount"
|
|
120
|
-
}
|