diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt index 8926f0b5f..7376866de 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Base.kt @@ -1,11 +1,21 @@ package org.cru.godtools.shared.tool.parser.model +import kotlin.experimental.ExperimentalObjCRefinement +import kotlin.js.ExperimentalJsExport +import kotlin.js.JsExport +import kotlin.native.HiddenFromObjC +import org.ccci.gto.support.androidx.annotation.RestrictTo +import org.ccci.gto.support.androidx.annotation.RestrictToScope + +@OptIn(ExperimentalJsExport::class, ExperimentalObjCRefinement::class) interface Base { - val manifest: Manifest - val stylesParent: Styles? + @HiddenFromObjC + @JsExport.Ignore + @get:RestrictTo(RestrictToScope.LIBRARY) + val parent: Base? get() = null + val manifest: Manifest get() = checkNotNull(parent?.manifest) { "No manifest found in model ancestors" } } -val Base?.manifest get() = this?.manifest -val Base?.stylesParent get() = this?.stylesParent +val Base?.stylesParent: Styles? get() = this?.parent?.let { it as? Styles ?: it.stylesParent } internal fun Base.getResource(name: String?) = manifest.getResource(name) diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt index a1a3e8fb1..c5858c434 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/BaseModel.kt @@ -1,6 +1,3 @@ package org.cru.godtools.shared.tool.parser.model -abstract class BaseModel internal constructor(private val parent: Base? = null) : Base { - override val stylesParent get() = parent as? Styles ?: parent?.stylesParent - override val manifest get() = checkNotNull(parent?.manifest) { "No manifest found in model ancestors" } -} +abstract class BaseModel internal constructor(override val parent: Base? = null) : Base diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt index 14859b8c5..bf6be72d9 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/Styles.kt @@ -53,7 +53,7 @@ internal val Styles?.cardBackgroundColor get() = this?.cardBackgroundColor ?: Ma // region Multiselect styles internal val Styles?.multiselectOptionBackgroundColor - get() = this?.multiselectOptionBackgroundColor ?: manifest.backgroundColor + get() = this?.multiselectOptionBackgroundColor ?: this?.manifest.backgroundColor // endregion Multiselect styles // region Text styles diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt index a32173a84..0642d42fd 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/page/Page.kt @@ -49,6 +49,7 @@ import org.cru.godtools.shared.tool.parser.model.page.Page.Companion.DEFAULT_BAC import org.cru.godtools.shared.tool.parser.model.page.Page.Companion.DEFAULT_BACKGROUND_IMAGE_SCALE_TYPE import org.cru.godtools.shared.tool.parser.model.primaryColor import org.cru.godtools.shared.tool.parser.model.primaryTextColor +import org.cru.godtools.shared.tool.parser.model.stylesParent import org.cru.godtools.shared.tool.parser.model.textColor import org.cru.godtools.shared.tool.parser.model.textScale import org.cru.godtools.shared.tool.parser.model.toColorOrNull diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt index 804aa2a4c..dce027506 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/Hero.kt @@ -20,6 +20,7 @@ import org.cru.godtools.shared.tool.parser.model.parseContent import org.cru.godtools.shared.tool.parser.model.parseTextChild import org.cru.godtools.shared.tool.parser.model.primaryColor import org.cru.godtools.shared.tool.parser.model.stylesOverride +import org.cru.godtools.shared.tool.parser.model.stylesParent import org.cru.godtools.shared.tool.parser.xml.XmlPullParser private const val XML_HEADING = "heading" diff --git a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt index 4ab608d1b..e2caf6c51 100644 --- a/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt +++ b/module/parser/src/commonMain/kotlin/org/cru/godtools/shared/tool/parser/model/tract/TractPage.kt @@ -38,7 +38,6 @@ import org.cru.godtools.shared.tool.parser.model.XML_TEXT_COLOR import org.cru.godtools.shared.tool.parser.model.backgroundColor import org.cru.godtools.shared.tool.parser.model.contentTips import org.cru.godtools.shared.tool.parser.model.getResource -import org.cru.godtools.shared.tool.parser.model.manifest import org.cru.godtools.shared.tool.parser.model.page.Page import org.cru.godtools.shared.tool.parser.model.parseContent import org.cru.godtools.shared.tool.parser.model.parseTextChild @@ -317,6 +316,6 @@ class TractPage : Page { } @get:AndroidColorInt -val Card?.backgroundColor get() = this?.backgroundColor ?: manifest.backgroundColor +val Card?.backgroundColor get() = this?.backgroundColor ?: this?.manifest.backgroundColor val Card?.backgroundImageGravity get() = this?.backgroundImageGravity ?: Card.DEFAULT_BACKGROUND_IMAGE_GRAVITY val Card?.backgroundImageScaleType get() = this?.backgroundImageScaleType ?: Card.DEFAULT_BACKGROUND_IMAGE_SCALE_TYPE diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt index 378aa0e89..ca05f31e1 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/ButtonTest.kt @@ -22,7 +22,7 @@ import org.cru.godtools.shared.tool.state.State @RunOnAndroidWith(AndroidJUnit4::class) class ButtonTest : UsesResources() { - private val parent = object : BaseModel(), Styles { + private val parentObj = object : BaseModel(), Styles { override lateinit var buttonStyle: Button.Style override var primaryColor = TestColors.BLACK override var primaryTextColor = TestColors.BLACK @@ -151,16 +151,16 @@ class ButtonTest : UsesResources() { // region Property - style @Test fun testButtonStyleUtilizesStylesDefault() { - with(Button(parent)) { - parent.buttonStyle = Button.Style.CONTAINED + with(Button(parentObj)) { + parentObj.buttonStyle = Button.Style.CONTAINED assertEquals(Button.Style.CONTAINED, style) - parent.buttonStyle = Button.Style.OUTLINED + parentObj.buttonStyle = Button.Style.OUTLINED assertEquals(Button.Style.OUTLINED, style) } - parent.buttonStyle = Button.Style.CONTAINED - with(Button(parent, style = Button.Style.OUTLINED)) { - assertNotEquals(parent.buttonStyle, style) + parentObj.buttonStyle = Button.Style.CONTAINED + with(Button(parentObj, style = Button.Style.OUTLINED)) { + assertNotEquals(parentObj.buttonStyle, style) assertEquals(Button.Style.OUTLINED, style) } } @@ -194,17 +194,17 @@ class ButtonTest : UsesResources() { // region Property - text - textAlign @Test fun testButtonTextTextAlignFallbackBehavior() { - parent.textAlign = Text.Align.START + parentObj.textAlign = Text.Align.START // Buttons default to center aligned text - with(Button(parent, text = { Text(it) })) { - assertNotEquals(parent.textAlign, text.textAlign) + with(Button(parentObj, text = { Text(it) })) { + assertNotEquals(parentObj.textAlign, text.textAlign) assertEquals(Text.Align.CENTER, text.textAlign) } // Text Align can still be overridden on the text element - with(Button(parent, text = { Text(it, textAlign = Text.Align.END) })) { - assertNotEquals(parent.textAlign, text.textAlign) + with(Button(parentObj, text = { Text(it, textAlign = Text.Align.END) })) { + assertNotEquals(parentObj.textAlign, text.textAlign) assertEquals(Text.Align.END, text.textAlign) } } @@ -213,39 +213,39 @@ class ButtonTest : UsesResources() { // region Property - text - textColor @Test fun testButtonTextColorFallbackBehaviorContained() { - parent.primaryColor = TestColors.RED - parent.primaryTextColor = TestColors.GREEN + parentObj.primaryColor = TestColors.RED + parentObj.primaryTextColor = TestColors.GREEN - with(Button(parent, style = Button.Style.CONTAINED, text = { Text(it) })) { - assertNotEquals(parent.primaryColor, text.textColor) - assertNotEquals(parent.textColor, text.textColor) + with(Button(parentObj, style = Button.Style.CONTAINED, text = { Text(it) })) { + assertNotEquals(parentObj.primaryColor, text.textColor) + assertNotEquals(parentObj.textColor, text.textColor) assertNotEquals(buttonColor, text.textColor) - assertEquals(parent.primaryTextColor, text.textColor) + assertEquals(parentObj.primaryTextColor, text.textColor) assertEquals(TestColors.GREEN, text.textColor) } - with(Button(parent, style = Button.Style.CONTAINED, text = { Text(it, textColor = TestColors.BLUE) })) { - assertNotEquals(parent.primaryTextColor, text.textColor) + with(Button(parentObj, style = Button.Style.CONTAINED, text = { Text(it, textColor = TestColors.BLUE) })) { + assertNotEquals(parentObj.primaryTextColor, text.textColor) assertEquals(TestColors.BLUE, text.textColor) } } @Test fun testButtonTextColorFallbackBehaviorOutlined() { - parent.primaryColor = TestColors.RED - parent.primaryTextColor = TestColors.RED + parentObj.primaryColor = TestColors.RED + parentObj.primaryTextColor = TestColors.RED - with(Button(parent, style = Button.Style.OUTLINED, color = TestColors.GREEN, text = { Text(it) })) { - assertNotEquals(parent.primaryColor, text.textColor) - assertNotEquals(parent.primaryTextColor, text.textColor) - assertNotEquals(parent.textColor, text.textColor) + with(Button(parentObj, style = Button.Style.OUTLINED, color = TestColors.GREEN, text = { Text(it) })) { + assertNotEquals(parentObj.primaryColor, text.textColor) + assertNotEquals(parentObj.primaryTextColor, text.textColor) + assertNotEquals(parentObj.textColor, text.textColor) assertEquals(buttonColor, text.textColor) assertEquals(TestColors.GREEN, text.textColor) } with( Button( - parent, + parentObj, style = Button.Style.OUTLINED, color = TestColors.RED, text = { Text(it, textColor = TestColors.GREEN) } diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt index e05bd5779..9be701389 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/StylesTest.kt @@ -7,9 +7,6 @@ import kotlin.test.assertNull class StylesTest { private val parent by lazy { object : Styles { - override val stylesParent: Styles? = null - override val manifest get() = TODO() - override var primaryColor = TestColors.RED override var primaryTextColor = TestColors.RED diff --git a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt index 84543df48..d954ae987 100644 --- a/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt +++ b/module/parser/src/commonTest/kotlin/org/cru/godtools/shared/tool/parser/model/tract/HeroTest.kt @@ -20,6 +20,7 @@ import org.cru.godtools.shared.tool.parser.model.Paragraph import org.cru.godtools.shared.tool.parser.model.Tabs import org.cru.godtools.shared.tool.parser.model.TestColors import org.cru.godtools.shared.tool.parser.model.Text +import org.cru.godtools.shared.tool.parser.model.stylesParent import org.cru.godtools.shared.tool.parser.withDeviceType @RunOnAndroidWith(AndroidJUnit4::class)