-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement a new stack widget. Signed-off-by: Lentumunai-Mark <[email protected]> * Add background color opacity. Signed-off-by: Lentumunai-Mark <[email protected]> * Adjust box background to make it configurable. Signed-off-by: Lentumunai-Mark <[email protected]> * Add stack view test. Signed-off-by: Lentumunai-Mark <[email protected]> * Interpolate child properties. Signed-off-by: Lentumunai-Mark <[email protected]> * Add stack widget documentation * Update stack widget doc formatting * Update ViewType.kt --------- Signed-off-by: Lentumunai-Mark <[email protected]> Co-authored-by: Benjamin Mwalimu <[email protected]>
- Loading branch information
1 parent
1d82052
commit 7057c38
Showing
9 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...src/main/java/org/smartregister/fhircore/engine/configuration/view/StackViewProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021-2024 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.engine.configuration.view | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.serialization.Serializable | ||
import org.smartregister.fhircore.engine.domain.model.ViewType | ||
import org.smartregister.fhircore.engine.util.extension.interpolate | ||
|
||
@Serializable | ||
@Parcelize | ||
data class StackViewProperties( | ||
override val viewType: ViewType = ViewType.STACK, | ||
override val weight: Float = 0f, | ||
override val backgroundColor: String? = "#FFFFFF", | ||
override val padding: Int = 0, | ||
override val borderRadius: Int = 0, | ||
override val alignment: ViewAlignment = ViewAlignment.NONE, | ||
override val fillMaxWidth: Boolean = false, | ||
override val fillMaxHeight: Boolean = false, | ||
override val clickable: String = "false", | ||
override val visible: String = "true", | ||
val opacity: Float = 0f, | ||
val size: Int? = 0, | ||
val children: List<ViewProperties> = emptyList(), | ||
) : ViewProperties(), Parcelable { | ||
override fun interpolate(computedValuesMap: Map<String, Any>): StackViewProperties { | ||
return this.copy( | ||
backgroundColor = backgroundColor?.interpolate(computedValuesMap), | ||
visible = visible.interpolate(computedValuesMap), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,4 +70,8 @@ enum class ViewAlignment { | |
END, | ||
CENTER, | ||
NONE, | ||
TOPSTART, | ||
TOPEND, | ||
BOTTOMSTART, | ||
BOTTOMEND, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...t/java/org/smartregister/fhircore/quest/integration/ui/shared/components/StackViewTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021-2024 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.quest.integration.ui.shared.components | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.navigation.compose.rememberNavController | ||
import org.hl7.fhir.r4.model.ResourceType | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.smartregister.fhircore.engine.configuration.view.StackViewProperties | ||
import org.smartregister.fhircore.engine.configuration.view.ViewAlignment | ||
import org.smartregister.fhircore.engine.domain.model.ResourceData | ||
import org.smartregister.fhircore.quest.ui.shared.components.STACK_VIEW_TEST_TAG | ||
import org.smartregister.fhircore.quest.ui.shared.components.StackView | ||
|
||
class StackViewTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testStackViewIsRendered() { | ||
val stackViewProperties = StackViewProperties(alignment = ViewAlignment.CENTER, size = 250) | ||
composeTestRule.setContent { | ||
StackView( | ||
modifier = Modifier, | ||
stackViewProperties = stackViewProperties, | ||
resourceData = ResourceData("", ResourceType.Patient, emptyMap()), | ||
navController = rememberNavController(), | ||
) | ||
} | ||
composeTestRule.onNodeWithTag(STACK_VIEW_TEST_TAG).assertExists() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...id/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/components/StackView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2021-2024 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.quest.ui.shared.components | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import androidx.navigation.compose.rememberNavController | ||
import org.hl7.fhir.r4.model.ResourceType | ||
import org.smartregister.fhircore.engine.configuration.view.StackViewProperties | ||
import org.smartregister.fhircore.engine.configuration.view.ViewAlignment | ||
import org.smartregister.fhircore.engine.domain.model.ResourceData | ||
import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundExcludeGenerated | ||
import org.smartregister.fhircore.engine.util.extension.parseColor | ||
|
||
const val STACK_VIEW_TEST_TAG = "stackViewTestTag" | ||
|
||
@Composable | ||
fun StackView( | ||
modifier: Modifier, | ||
stackViewProperties: StackViewProperties, | ||
resourceData: ResourceData, | ||
navController: NavController, | ||
) { | ||
val backgroundColor = stackViewProperties.backgroundColor.parseColor() | ||
val size = stackViewProperties.size | ||
|
||
Box( | ||
modifier = | ||
Modifier.background(backgroundColor.copy(alpha = stackViewProperties.opacity)) | ||
.size(size!!.dp) | ||
.testTag(STACK_VIEW_TEST_TAG), | ||
contentAlignment = castViewAlignment(stackViewProperties.alignment), | ||
) { | ||
stackViewProperties.children.forEach { child -> | ||
GenerateView( | ||
modifier = generateModifier(viewProperties = child), | ||
properties = child.interpolate(resourceData.computedValuesMap), | ||
resourceData = resourceData, | ||
navController = navController, | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun castViewAlignment( | ||
viewAlignment: ViewAlignment, | ||
): Alignment { | ||
return when (viewAlignment) { | ||
ViewAlignment.TOPSTART -> Alignment.TopStart | ||
ViewAlignment.TOPEND -> Alignment.TopEnd | ||
ViewAlignment.CENTER -> Alignment.Center | ||
ViewAlignment.BOTTOMSTART -> Alignment.BottomStart | ||
ViewAlignment.BOTTOMEND -> Alignment.BottomEnd | ||
else -> { | ||
Alignment.Center | ||
} | ||
} | ||
} | ||
|
||
@PreviewWithBackgroundExcludeGenerated | ||
@Composable | ||
private fun PreviewStack() { | ||
StackView( | ||
stackViewProperties = | ||
StackViewProperties( | ||
opacity = 0.2f, | ||
size = 250, | ||
backgroundColor = "successColor", | ||
), | ||
modifier = Modifier, | ||
navController = rememberNavController(), | ||
resourceData = | ||
ResourceData( | ||
baseResourceId = "baseId", | ||
baseResourceType = ResourceType.Patient, | ||
computedValuesMap = emptyMap(), | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters