Merge "Scroll to top when opening more settings page" into main
This commit is contained in:
@@ -26,9 +26,13 @@ import android.os.Bundle
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
@@ -227,6 +231,7 @@ class DeviceDetailsFragmentFormatterImpl(
|
||||
|
||||
dashboardFragment.lifecycleScope.launch {
|
||||
if (isLoading) {
|
||||
scrollToTop()
|
||||
dashboardFragment.setLoading(false, false)
|
||||
isLoading = false
|
||||
}
|
||||
@@ -495,6 +500,19 @@ class DeviceDetailsFragmentFormatterImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun scrollToTop() {
|
||||
// Temporary fix to make sure the screen is scroll to the top when rendering.
|
||||
ComposePreference(context).apply {
|
||||
order = -1
|
||||
isEnabled = false
|
||||
isSelectable = false
|
||||
setContent { Spacer(modifier = Modifier.height(1.dp)) }
|
||||
}.also {
|
||||
dashboardFragment.preferenceScreen.addPreference(it)
|
||||
dashboardFragment.scrollToPreference(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPreferenceKey(settingId: Int) = "DEVICE_SETTING_${settingId}"
|
||||
|
||||
private class SpotlightPreference(context: Context) : Preference(context) {
|
||||
|
@@ -404,7 +404,7 @@ class DeviceDetailsFragmentFormatterTest {
|
||||
for (i in 0..<fragment.preferenceScreen.preferenceCount) {
|
||||
prefs.add(fragment.preferenceScreen.getPreference(i))
|
||||
}
|
||||
return prefs
|
||||
return prefs.filter { it.key != null }
|
||||
}
|
||||
|
||||
class TestFragment(context: Context) : DashboardFragment() {
|
||||
|
Reference in New Issue
Block a user