TP-66097 Give support to add children subscribed events info in parent view dataMap (#436)
This commit is contained in:
@@ -37,6 +37,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.navi.uitron.demo.stringToUiTronResponse
|
||||
import com.navi.uitron.demo.theme.PinkCC2FD5
|
||||
import com.navi.uitron.demo.theme.UiTronTheme
|
||||
@@ -46,7 +47,7 @@ import com.navi.uitron.render.UiTronRenderer
|
||||
import com.navi.uitron.viewmodel.UiTronViewModel
|
||||
|
||||
@Composable
|
||||
fun PlaygroundScreen() {
|
||||
fun PlaygroundScreen(viewModel: UiTronViewModel = hiltViewModel()) {
|
||||
val clipboardManager: ClipboardManager = LocalClipboardManager.current
|
||||
val field = remember { mutableStateOf("") }
|
||||
|
||||
@@ -141,7 +142,7 @@ fun PlaygroundScreen() {
|
||||
null
|
||||
}
|
||||
uiTronResponse?.let {
|
||||
UiTronRenderer(uiTronResponse.data, uiTronViewModel = UiTronViewModel())
|
||||
UiTronRenderer(uiTronResponse.data, uiTronViewModel = viewModel)
|
||||
.Render(composeViews = uiTronResponse.parentComposeView.orEmpty())
|
||||
}
|
||||
?: kotlin.run {
|
||||
|
||||
@@ -21,10 +21,12 @@ open class UiTronData : Parcelable {
|
||||
val slideData: SlideData? = null
|
||||
val lifecycleActionData: LifecycleActionData? = null
|
||||
var subscribedEvents: List<SubscribedEventInfo?>? = null
|
||||
var childrenSubscribedEvents: List<ChildrenSubscribedEventsInfo?>? = null
|
||||
|
||||
open fun copyNonNull(data: UiTronData?) {
|
||||
onClick = data?.onClick ?: onClick
|
||||
subscribedEvents = data?.subscribedEvents ?: subscribedEvents
|
||||
childrenSubscribedEvents = data?.childrenSubscribedEvents ?: childrenSubscribedEvents
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +65,12 @@ data class SubscribedEventInfo(
|
||||
val stateKey: String? = null,
|
||||
) : Parcelable
|
||||
|
||||
data class ChildrenSubscribedEventsInfo(
|
||||
val layoutId: String? = null,
|
||||
val viewType: String? = null,
|
||||
val subscribedEvents: List<SubscribedEventInfo?>? = null
|
||||
)
|
||||
|
||||
@Parcelize
|
||||
data class SubscriberEventData(
|
||||
val layoutId: String? = null,
|
||||
|
||||
@@ -57,7 +57,8 @@ open class BaseProperty(
|
||||
var isSensitive: Boolean? = null,
|
||||
var animate: Animate? = null,
|
||||
var transformOrigin: TransFormOrigin? = null,
|
||||
var propertyAnimator: List<PropertyAnimator?>? = null
|
||||
var propertyAnimator: List<PropertyAnimator?>? = null,
|
||||
val disableClick: Boolean? = false
|
||||
) : Parcelable {
|
||||
open fun copyNonNullFrom(property: BaseProperty?) {
|
||||
property?.width?.let { width = it }
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.lifecycle.LifecycleEventObserver
|
||||
import com.navi.uitron.UiTronSdkManager
|
||||
import com.navi.uitron.model.action.MvelAction
|
||||
import com.navi.uitron.model.data.LifecycleActionData
|
||||
import com.navi.uitron.model.data.SubscribedEventInfo
|
||||
import com.navi.uitron.model.data.SubscriberEventData
|
||||
import com.navi.uitron.model.data.UiTronAction
|
||||
import com.navi.uitron.model.data.UiTronData
|
||||
@@ -146,24 +147,42 @@ interface Renderer<T : BaseProperty> {
|
||||
uiTronViewModel: UiTronViewModel
|
||||
) {
|
||||
uiTronData?.subscribedEvents?.filterNotNull()?.forEach { event ->
|
||||
val eventSubscribers: MutableList<SubscriberEventData> =
|
||||
uiTronViewModel.handle[event.eventName.plus(BaseProperty.EVENT_SUFFIX)]
|
||||
?: mutableListOf()
|
||||
eventSubscribers
|
||||
.any { subscriberData -> subscriberData.layoutId == property.layoutId }
|
||||
.let { isLayoutIdExist ->
|
||||
if (isLayoutIdExist.not()) {
|
||||
eventSubscribers.add(
|
||||
SubscriberEventData(
|
||||
layoutId = property.layoutId,
|
||||
viewType = property.viewType,
|
||||
stateKey = event.stateKey
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
uiTronViewModel.handle[event.eventName.plus(BaseProperty.EVENT_SUFFIX)] =
|
||||
eventSubscribers
|
||||
updateEventSubscribers(uiTronViewModel, event, property.layoutId, property.viewType)
|
||||
}
|
||||
uiTronData?.childrenSubscribedEvents?.filterNotNull()?.forEach { eventInfo ->
|
||||
eventInfo.subscribedEvents?.filterNotNull()?.forEach { event ->
|
||||
updateEventSubscribers(
|
||||
uiTronViewModel,
|
||||
event,
|
||||
eventInfo.layoutId,
|
||||
eventInfo.viewType
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateEventSubscribers(
|
||||
uiTronViewModel: UiTronViewModel,
|
||||
event: SubscribedEventInfo,
|
||||
layoutId: String?,
|
||||
viewType: String?
|
||||
) {
|
||||
val eventSubscribers: MutableList<SubscriberEventData> =
|
||||
uiTronViewModel.handle[event.eventName.plus(BaseProperty.EVENT_SUFFIX)]
|
||||
?: mutableListOf()
|
||||
eventSubscribers
|
||||
.any { subscriberData -> subscriberData.layoutId == layoutId }
|
||||
.let { isLayoutIdExist ->
|
||||
if (isLayoutIdExist.not()) {
|
||||
eventSubscribers.add(
|
||||
SubscriberEventData(
|
||||
layoutId = layoutId,
|
||||
viewType = viewType,
|
||||
stateKey = event.stateKey
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
uiTronViewModel.handle[event.eventName.plus(BaseProperty.EVENT_SUFFIX)] = eventSubscribers
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,6 +360,8 @@ fun Modifier.customClickable(
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
} else if (property?.disableClick.orFalse()) {
|
||||
clickable(enabled = false) {}
|
||||
} else return@composed this
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user