TP-49814 : Made header and footer renderers for list of widgets (#8794)
This commit is contained in:
@@ -25,8 +25,10 @@ data class ApScreenStructure(
|
||||
val screenBehaviourType: String? = null,
|
||||
val screenId: String? = null,
|
||||
val header: WidgetModelDefinition<UiTronResponse>? = null,
|
||||
val headerContent: WidgetGroup? = null,
|
||||
val content: ScreenContent? = null,
|
||||
val footer: WidgetModelDefinition<UiTronResponse>? = null,
|
||||
val footerContent: WidgetGroup? = null,
|
||||
val bottomSheets: List<ApScreenStructure>? = null,
|
||||
val toasts: List<WidgetModelDefinition<UiTronResponse>>? = null,
|
||||
val systemBackCta: UiTronActionData? = null,
|
||||
@@ -43,6 +45,12 @@ data class ScreenContent(
|
||||
val backgroundBrushData: BrushData? = null
|
||||
)
|
||||
|
||||
data class WidgetGroup(
|
||||
val widgets: List<WidgetModelDefinition<UiTronResponse>>? = null,
|
||||
val backgroundColor: String? = DEFAULT_BACKGROUND_COLOR
|
||||
)
|
||||
|
||||
|
||||
data class RenderActions(
|
||||
val preRenderAction: UiTronActionData? = null,
|
||||
val postRenderAction: UiTronActionData? = null
|
||||
|
||||
@@ -10,7 +10,6 @@ package com.navi.ap.common.ui.renderer
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.LocalOverscrollConfiguration
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Scaffold
|
||||
@@ -25,7 +24,6 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import com.navi.ap.common.models.ApScreenDefinitionStructure
|
||||
import com.navi.ap.common.viewmodel.LambdaVM
|
||||
import com.navi.ap.common.widgetfactory.WidgetRenderer
|
||||
import com.navi.ap.utils.constants.SCREEN_TYPE
|
||||
import com.navi.ap.utils.constants.noLoaderScreenTypes
|
||||
import com.navi.ap.utils.hideKeyboard
|
||||
@@ -47,15 +45,11 @@ fun ScaffoldRenderer(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.pointerInput(Unit) {
|
||||
detectTapGestures(
|
||||
onTap = {
|
||||
hideKeyboard(
|
||||
context = context,
|
||||
view = view,
|
||||
keyBoardController = keyBoardController
|
||||
)
|
||||
}
|
||||
)
|
||||
detectTapGestures(onTap = {
|
||||
hideKeyboard(
|
||||
context = context, view = view, keyBoardController = keyBoardController
|
||||
)
|
||||
})
|
||||
}
|
||||
.setBackground(
|
||||
backgroundColor = apScreenDefinitionStructure.screenData?.screenStructure?.content?.backgroundColor,
|
||||
@@ -63,34 +57,32 @@ fun ScaffoldRenderer(
|
||||
brushData = apScreenDefinitionStructure.screenData?.screenStructure?.content?.backgroundBrushData
|
||||
),
|
||||
topBar = {
|
||||
apScreenDefinitionStructure.screenData?.screenStructure?.header?.let { uiTronHeader ->
|
||||
WidgetRenderer(widget = uiTronHeader, viewModel = viewModel)
|
||||
}
|
||||
WidgetGroupRenderer(
|
||||
widgetGroup = apScreenDefinitionStructure.screenData?.screenStructure?.headerContent,
|
||||
widget = apScreenDefinitionStructure.screenData?.screenStructure?.header,
|
||||
viewModel = viewModel
|
||||
)
|
||||
},
|
||||
content = {
|
||||
CompositionLocalProvider(LocalOverscrollConfiguration provides null) {
|
||||
val scrollEnabled = noLoaderScreenTypes.contains(
|
||||
apScreenDefinitionStructure.screenData?.metaData?.get(SCREEN_TYPE)
|
||||
).not()
|
||||
Column(
|
||||
modifier =
|
||||
Modifier
|
||||
WidgetListRenderer(
|
||||
viewModel = viewModel,
|
||||
widgetList = apScreenDefinitionStructure.screenData?.screenStructure?.content?.widgets,
|
||||
modifier = Modifier
|
||||
.padding(it)
|
||||
.setVerticalScroll(ScrollData(enabled = scrollEnabled))
|
||||
) {
|
||||
apScreenDefinitionStructure.screenData?.screenStructure?.content?.widgets?.forEach { widget ->
|
||||
WidgetRenderer(
|
||||
widget = widget,
|
||||
viewModel = viewModel
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
bottomBar = {
|
||||
apScreenDefinitionStructure.screenData?.screenStructure?.footer?.let { uiTronFooter ->
|
||||
WidgetRenderer(widget = uiTronFooter, viewModel = viewModel)
|
||||
}
|
||||
WidgetGroupRenderer(
|
||||
widgetGroup = apScreenDefinitionStructure.screenData?.screenStructure?.footerContent,
|
||||
widget = apScreenDefinitionStructure.screenData?.screenStructure?.footer,
|
||||
viewModel = viewModel
|
||||
)
|
||||
},
|
||||
backgroundColor =
|
||||
Color(
|
||||
|
||||
@@ -105,7 +105,7 @@ fun StickyHeaderAndFooterRenderer(
|
||||
.zIndex(1.5f)
|
||||
.graphicsLayer {
|
||||
alpha = 1 - animatedAlpha
|
||||
translationY = - scrollYPosition
|
||||
translationY = -scrollYPosition
|
||||
}
|
||||
.onGloballyPositioned {
|
||||
headerHeight = it.size.height.toFloat()
|
||||
@@ -115,8 +115,10 @@ fun StickyHeaderAndFooterRenderer(
|
||||
start.linkTo(parent.start)
|
||||
end.linkTo(parent.end)
|
||||
}) {
|
||||
WidgetRenderer(
|
||||
screenDefinitionStructure.screenData?.screenStructure?.header, viewModel
|
||||
WidgetGroupRenderer(
|
||||
widgetGroup = screenDefinitionStructure.screenData?.screenStructure?.headerContent,
|
||||
widget = screenDefinitionStructure.screenData?.screenStructure?.header,
|
||||
viewModel = viewModel
|
||||
)
|
||||
}
|
||||
|
||||
@@ -142,8 +144,10 @@ fun StickyHeaderAndFooterRenderer(
|
||||
start.linkTo(parent.start, margin = 0.dp)
|
||||
end.linkTo(parent.end, margin = 0.dp)
|
||||
}) {
|
||||
WidgetRenderer(
|
||||
screenDefinitionStructure.screenData?.screenStructure?.footer, viewModel
|
||||
WidgetGroupRenderer(
|
||||
widgetGroup = screenDefinitionStructure.screenData?.screenStructure?.footerContent,
|
||||
widget = screenDefinitionStructure.screenData?.screenStructure?.footer,
|
||||
viewModel = viewModel
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.navi.ap.common.ui.renderer
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import com.navi.ap.common.models.WidgetGroup
|
||||
import com.navi.ap.common.models.WidgetModelDefinition
|
||||
import com.navi.ap.common.viewmodel.LambdaVM
|
||||
import com.navi.ap.common.widgetfactory.WidgetRenderer
|
||||
import com.navi.design.utils.parseColorSafe
|
||||
import com.navi.uitron.model.UiTronResponse
|
||||
|
||||
@Composable
|
||||
fun WidgetGroupRenderer(
|
||||
widgetGroup : WidgetGroup?,
|
||||
widget: WidgetModelDefinition<UiTronResponse>?,
|
||||
viewModel: LambdaVM
|
||||
) {
|
||||
widget?.let {
|
||||
WidgetRenderer(widget = it, viewModel = viewModel)
|
||||
} ?: widgetGroup?.let { el ->
|
||||
WidgetListRenderer(
|
||||
viewModel = viewModel,
|
||||
widgetList = el.widgets,
|
||||
modifier = Modifier.background(Color(el.backgroundColor.parseColorSafe()))
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.navi.ap.common.ui.renderer
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.navi.ap.common.models.WidgetModelDefinition
|
||||
import com.navi.ap.common.viewmodel.LambdaVM
|
||||
import com.navi.ap.common.widgetfactory.WidgetRenderer
|
||||
import com.navi.uitron.model.UiTronResponse
|
||||
|
||||
@Composable
|
||||
fun WidgetListRenderer(
|
||||
viewModel: LambdaVM,
|
||||
widgetList: List<WidgetModelDefinition<UiTronResponse>>? = null,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
|
||||
Column(modifier = modifier) {
|
||||
widgetList?.forEach { widget ->
|
||||
WidgetRenderer(widget = widget, viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,9 @@ import com.navi.ap.common.repository.LambdaRepository
|
||||
import com.navi.ap.utils.cacheImages
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class ApSharedVM @Inject constructor(repository: LambdaRepository) :
|
||||
@@ -66,6 +66,20 @@ class ApSharedVM @Inject constructor(repository: LambdaRepository) :
|
||||
cacheImages(uiTronResponse = it.widgetData)
|
||||
}
|
||||
}
|
||||
|
||||
screenDefinitionStructure?.screenData?.screenStructure?.headerContent?.widgets?.forEach {
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
cacheImages(uiTronResponse = it.widgetData)
|
||||
}
|
||||
}
|
||||
|
||||
screenDefinitionStructure?.screenData?.screenStructure?.footerContent?.widgets?.forEach {
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
cacheImages(uiTronResponse = it.widgetData)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun setBackScreenId(backScreenId : String){
|
||||
|
||||
@@ -79,6 +79,7 @@ fun initWidgetMetaDataAndActions(
|
||||
?.postRenderAction
|
||||
)
|
||||
|
||||
|
||||
viewModel.saveWidgetMetaData(apScreenDefinitionStructure.screenData?.screenStructure?.footer)
|
||||
viewModel.handleActions(
|
||||
apScreenDefinitionStructure.screenData
|
||||
@@ -97,6 +98,24 @@ fun initWidgetMetaDataAndActions(
|
||||
viewModel.handleActions(it.widgetRenderActions?.postRenderAction)
|
||||
}
|
||||
|
||||
apScreenDefinitionStructure.screenData
|
||||
?.screenStructure
|
||||
?.headerContent
|
||||
?.widgets
|
||||
?.forEach(viewModel::saveWidgetMetaData)
|
||||
apScreenDefinitionStructure.screenData?.screenStructure?.headerContent?.widgets?.forEach {
|
||||
viewModel.handleActions(it.widgetRenderActions?.postRenderAction)
|
||||
}
|
||||
|
||||
apScreenDefinitionStructure.screenData
|
||||
?.screenStructure
|
||||
?.footerContent
|
||||
?.widgets
|
||||
?.forEach(viewModel::saveWidgetMetaData)
|
||||
apScreenDefinitionStructure.screenData?.screenStructure?.footerContent?.widgets?.forEach {
|
||||
viewModel.handleActions(it.widgetRenderActions?.postRenderAction)
|
||||
}
|
||||
|
||||
apScreenDefinitionStructure.screenData?.screenStructure?.bottomSheets?.forEach { bottomSheet ->
|
||||
bottomSheet.content?.widgets?.forEach(viewModel::saveWidgetMetaData)
|
||||
bottomSheet.content?.widgets?.forEach {
|
||||
|
||||
Reference in New Issue
Block a user