diff --git a/sample/mpp-library/src/commonMain/kotlin/App.kt b/sample/mpp-library/src/commonMain/kotlin/App.kt index cd1cf0e1..a914a2c6 100644 --- a/sample/mpp-library/src/commonMain/kotlin/App.kt +++ b/sample/mpp-library/src/commonMain/kotlin/App.kt @@ -283,7 +283,8 @@ class App() : BaseApplication() { factory[LoginScreen.Id.EmailInputId] = FlatInputViewFactory( textStyle = TextStyle( size = 16, - color = Color(0x16171AFF) + color = Color(0x16171AFF), + font = MR.fonts.GrenzeGotisch.regular ), backgroundColor = Color(0xF5F5F5FF) ) @@ -310,7 +311,8 @@ class App() : BaseApplication() { factory[InputWidget.DefaultCategory] = SystemInputViewFactory( textStyle = TextStyle( size = 16, - color = Color(0x16171AFF) + color = Color(0x16171AFF), + font = MR.fonts.GrenzeGotisch.regular ) ) factory[TabsWidget.DefaultCategory] = SystemTabsViewFactory( diff --git a/sample/mpp-library/src/commonMain/resources/MR/fonts/GrenzeGotisch-Regular.ttf b/sample/mpp-library/src/commonMain/resources/MR/fonts/GrenzeGotisch-Regular.ttf new file mode 100644 index 00000000..3552e82f Binary files /dev/null and b/sample/mpp-library/src/commonMain/resources/MR/fonts/GrenzeGotisch-Regular.ttf differ diff --git a/widgets-flat/src/iosMain/kotlin/dev/icerock/moko/widgets/flat/FlatInputViewFactory.kt b/widgets-flat/src/iosMain/kotlin/dev/icerock/moko/widgets/flat/FlatInputViewFactory.kt index ddc60d0f..15d0a572 100644 --- a/widgets-flat/src/iosMain/kotlin/dev/icerock/moko/widgets/flat/FlatInputViewFactory.kt +++ b/widgets-flat/src/iosMain/kotlin/dev/icerock/moko/widgets/flat/FlatInputViewFactory.kt @@ -14,6 +14,7 @@ import dev.icerock.moko.widgets.core.ViewFactoryContext import dev.icerock.moko.widgets.core.style.view.MarginValues import dev.icerock.moko.widgets.core.style.view.TextStyle import dev.icerock.moko.widgets.core.style.view.WidgetSize +import dev.icerock.moko.widgets.core.utils.applyTextStyleIfNeeded import dev.icerock.moko.widgets.core.utils.bind import dev.icerock.moko.widgets.core.utils.setEventHandler import kotlinx.cinterop.readValue @@ -36,13 +37,8 @@ actual class FlatInputViewFactory actual constructor( val flatInputField = FlatInputField(frame = CGRectZero.readValue()) val textField = flatInputField.textField()!! - textStyle?.color?.also { - textField.textColor = it.toUIColor() - } - textStyle?.size?.also { - textField.font = UIFont.systemFontOfSize(it.toDouble()) - } - + textField.applyTextStyleIfNeeded(textStyle) + widget.field.data.bind { if (textField.text == it) return@bind textField.text = it diff --git a/widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/core/style/TextViewExt.kt b/widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/core/style/TextViewExt.kt index 2878c85d..02398867 100644 --- a/widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/core/style/TextViewExt.kt +++ b/widgets/src/androidMain/kotlin/dev/icerock/moko/widgets/core/style/TextViewExt.kt @@ -30,5 +30,6 @@ fun TextView.applyCommonTextStyleIfNeeded(textStyle: TextStyle<*>?) { if (textStyle == null) return textStyle.size?.also { textSize = it.toFloat() } + textStyle.font?.also { this.setTypeface( it.getTypeface(context)) } textStyle.fontStyle?.also { applyFontStyle(it) } } diff --git a/widgets/src/commonMain/kotlin/dev/icerock/moko/widgets/core/style/view/TextStyle.kt b/widgets/src/commonMain/kotlin/dev/icerock/moko/widgets/core/style/view/TextStyle.kt index 4e0e1c5e..f3797570 100644 --- a/widgets/src/commonMain/kotlin/dev/icerock/moko/widgets/core/style/view/TextStyle.kt +++ b/widgets/src/commonMain/kotlin/dev/icerock/moko/widgets/core/style/view/TextStyle.kt @@ -4,8 +4,11 @@ package dev.icerock.moko.widgets.core.style.view +import dev.icerock.moko.resources.FontResource + data class TextStyle( val size: Int? = null, val color: C? = null, - val fontStyle: FontStyle? = null + val fontStyle: FontStyle? = null, + val font: FontResource? = null ) diff --git a/widgets/src/iosMain/kotlin/dev/icerock/moko/widgets/core/utils/TextStyleExt.kt b/widgets/src/iosMain/kotlin/dev/icerock/moko/widgets/core/utils/TextStyleExt.kt index 0ee5b0fa..2ffb3c3b 100644 --- a/widgets/src/iosMain/kotlin/dev/icerock/moko/widgets/core/utils/TextStyleExt.kt +++ b/widgets/src/iosMain/kotlin/dev/icerock/moko/widgets/core/utils/TextStyleExt.kt @@ -27,7 +27,11 @@ import platform.UIKit.UITextView fun TextStyle<*>.toUIFont(defaultFontSize: Double = 17.0): UIFont? { val styleSize = size?.toDouble() val fontStyle = fontStyle - if (fontStyle != null || styleSize != null) { + if(font != null){ + val fontSize = styleSize ?: defaultFontSize + return font.uiFont(fontSize) + } + else if (fontStyle != null || styleSize != null) { val fontSize = styleSize ?: defaultFontSize return when (fontStyle) { FontStyle.BOLD -> UIFont.boldSystemFontOfSize(fontSize = fontSize)