Introduce an EntryData interface to manage entry, page and highlight
info. Based on CompositionLocal version of EntryData, we pass the info to UI implementations for pages. Test: Manually test on deivce Bug: 253536111 Change-Id: I81f4b8b3f3f799bc472ec19d196f56c8b1f756e0
This commit is contained in:
@@ -19,6 +19,9 @@ package com.android.settingslib.spa.framework.common
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.ProvidedValue
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
@@ -28,6 +31,16 @@ import com.android.settingslib.spa.framework.compose.LocalNavController
|
||||
const val INJECT_ENTRY_NAME = "INJECT"
|
||||
const val ROOT_ENTRY_NAME = "ROOT"
|
||||
|
||||
interface EntryData {
|
||||
val pageId: String
|
||||
val entryId: String
|
||||
val isHighlighted: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
val LocalEntryDataProvider =
|
||||
compositionLocalOf<EntryData> { error("LocalEntryDataProvider: No Default Value!") }
|
||||
|
||||
/**
|
||||
* Defines data of a Settings entry.
|
||||
*/
|
||||
@@ -121,7 +134,22 @@ data class SettingsEntry(
|
||||
// TODO: Add highlight entry logic
|
||||
Toast.makeText(context, "entry $id highlighted", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
uiLayoutImpl(fullArgument(runtimeArguments))
|
||||
|
||||
CompositionLocalProvider(provideLocalEntryData()) {
|
||||
uiLayoutImpl(fullArgument(runtimeArguments))
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun provideLocalEntryData(): ProvidedValue<EntryData> {
|
||||
val controller = LocalNavController.current
|
||||
return LocalEntryDataProvider provides remember {
|
||||
object : EntryData {
|
||||
override val pageId = containerPage().id
|
||||
override val entryId = id
|
||||
override val isHighlighted = controller.highlightEntryId == id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user