mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-2990 Widgets | Fix | Do not show widget until its layout is defined (#1731)
This commit is contained in:
parent
51a11a48e1
commit
1ba4cd36c6
3 changed files with 23 additions and 3 deletions
|
@ -117,6 +117,7 @@ import com.anytypeio.anytype.presentation.widgets.WidgetId
|
|||
import com.anytypeio.anytype.presentation.widgets.WidgetSessionStateHolder
|
||||
import com.anytypeio.anytype.presentation.widgets.WidgetView
|
||||
import com.anytypeio.anytype.presentation.widgets.collection.Subscription
|
||||
import com.anytypeio.anytype.presentation.widgets.hasValidLayout
|
||||
import com.anytypeio.anytype.presentation.widgets.parseActiveViews
|
||||
import com.anytypeio.anytype.presentation.widgets.parseWidgets
|
||||
import javax.inject.Inject
|
||||
|
@ -426,7 +427,7 @@ class HomeScreenViewModel(
|
|||
viewModelScope.launch {
|
||||
widgets.filterNotNull().map { widgets ->
|
||||
val currentlyDisplayedViews = views.value
|
||||
widgets.map { widget ->
|
||||
widgets.filter { widget -> widget.hasValidLayout() }.map { widget ->
|
||||
when (widget) {
|
||||
is Widget.Link -> LinkWidgetContainer(
|
||||
widget = widget
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.anytypeio.anytype.core_models.ObjectWrapper
|
|||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.Struct
|
||||
import com.anytypeio.anytype.core_models.ext.asMap
|
||||
import com.anytypeio.anytype.presentation.objects.SupportedLayouts
|
||||
|
||||
sealed class Widget {
|
||||
|
||||
|
@ -94,6 +95,17 @@ sealed class Widget {
|
|||
}
|
||||
}
|
||||
|
||||
fun Widget.hasValidLayout() : Boolean {
|
||||
return when (val widgetSource = source) {
|
||||
is Widget.Source.Default -> {
|
||||
widgetSource.obj.layout != null && SupportedLayouts.layouts.contains(widgetSource.obj.layout)
|
||||
}
|
||||
is Widget.Source.Bundled -> {
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun List<Block>.parseActiveViews() : WidgetToActiveView {
|
||||
val result = mutableMapOf<WidgetId, WidgetActiveViewId>()
|
||||
forEach { block ->
|
||||
|
|
|
@ -2114,12 +2114,14 @@ class HomeScreenViewModelTest {
|
|||
val currentSourceObject = StubObject(
|
||||
id = "SOURCE OBJECT 1",
|
||||
links = emptyList(),
|
||||
objectType = ObjectTypeIds.PAGE
|
||||
objectType = ObjectTypeIds.PAGE,
|
||||
layout = ObjectType.Layout.BASIC.code.toDouble()
|
||||
)
|
||||
val newSourceObject = StubObject(
|
||||
id = "SOURCE OBJECT 2",
|
||||
links = emptyList(),
|
||||
objectType = ObjectTypeIds.PAGE
|
||||
objectType = ObjectTypeIds.PAGE,
|
||||
layout = ObjectType.Layout.BASIC.code.toDouble()
|
||||
)
|
||||
val sourceLink = StubLinkToObjectBlock(
|
||||
id = "SOURCE LINK",
|
||||
|
@ -2155,6 +2157,11 @@ class HomeScreenViewModelTest {
|
|||
delay(300)
|
||||
emit(
|
||||
listOf(
|
||||
Event.Command.Details.Set(
|
||||
context = WIDGET_OBJECT_ID,
|
||||
target = newSourceObject.id,
|
||||
details = Block.Fields(newSourceObject.map)
|
||||
),
|
||||
Event.Command.LinkGranularChange(
|
||||
context = WIDGET_OBJECT_ID,
|
||||
id = sourceLink.id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue