Improve feed gestures

This commit is contained in:
MM20
2026-01-06 21:50:28 +01:00
parent 7eb5f591d6
commit 93250bd07d
5 changed files with 66 additions and 27 deletions

View File

@@ -2,7 +2,6 @@ package de.mm20.launcher2.ui.launcher.scaffold
import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import androidx.activity.compose.LocalActivity
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Arrangement
@@ -19,6 +18,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@@ -34,7 +34,6 @@ import de.mm20.launcher2.feed.FeedService
import de.mm20.launcher2.preferences.feed.FeedSettings
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.ktx.toIntOffset
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
@@ -47,6 +46,8 @@ internal class FeedComponent(
override val permanent: Boolean = true
private var state = mutableIntStateOf(0)
@Composable
override fun Component(
modifier: Modifier,
@@ -79,18 +80,30 @@ internal class FeedComponent(
}
}
val enableScroll = state.currentComponent == this && progress > 0f && progress < 1f
val componentState = this.state.intValue
LaunchedEffect(enableScroll) {
if (enableScroll) {
LaunchedEffect(state.currentComponent == this && componentState < 2) {
if (state.currentComponent == this@FeedComponent && componentState < 2) {
feedConnection?.startScroll()
} else {
}
}
LaunchedEffect(componentState == 2 && progress > 0.5f) {
if (componentState == 2 && progress > 0.5f) {
feedConnection?.endScroll()
}
}
LaunchedEffect(progress) {
feedConnection?.onScroll(progress)
LaunchedEffect(componentState == 0) {
if (componentState == 0) {
feedConnection?.closeFeed()
}
}
LaunchedEffect(state.currentComponent == this, progress) {
if (state.currentComponent == this@FeedComponent) {
feedConnection?.onScroll(progress)
}
}
LaunchedEffect(feedProgress.floatValue) {
@@ -142,4 +155,25 @@ internal class FeedComponent(
.alpha(1f - state.currentProgress)
}
override suspend fun onPreActivate(state: LauncherScaffoldState) {
super.onPreActivate(state)
this.state.intValue = 2
}
override suspend fun onActivate(state: LauncherScaffoldState) {
super.onActivate(state)
this.state.intValue = 3
}
override suspend fun onDismiss(state: LauncherScaffoldState) {
super.onDismiss(state)
this.state.intValue = 0
}
override suspend fun onPreDismiss(state: LauncherScaffoldState) {
super.onPreDismiss(state)
this.state.intValue = 1
}
}

View File

@@ -1,6 +1,6 @@
# Feed
The feed is a personalized content page that lives to the left of your home screen, that can be
The feed is a personalized content page that lives to the left of your home screen, which can be
opened without leaving the launcher. Traditionally, launchers show the Google Discover feed here,
but there are other alternatives.

View File

@@ -54,6 +54,10 @@ export const UserGuideSidebar: DefaultTheme.SidebarItem[] = [
text: 'Weather',
link: '/docs/user-guide/integrations/weather',
},
{
text: 'Feed',
link: '/docs/user-guide/integrations/feed',
},
],
},
{

View File

@@ -29,6 +29,9 @@ interface FeedConnection {
fun startScroll()
fun endScroll()
fun onScroll(progress: Float)
fun openFeed()
fun closeFeed()
}
internal class FeedConnectionImpl(
@@ -77,6 +80,22 @@ internal class FeedConnectionImpl(
}
}
override fun openFeed() {
try {
overlay?.openOverlay(Flags)
} catch (e: RemoteException) {
CrashReporter.logException(e)
}
}
override fun closeFeed() {
try {
overlay?.closeOverlay(Flags)
} catch (e: RemoteException) {
CrashReporter.logException(e)
}
}
fun start() {
activity.lifecycle.addObserver(this)
val service = activity.packageManager.resolveService(serviceIntent, 0)

View File

@@ -1,18 +0,0 @@
package de.mm20.launcher2.feed
import amirz.aidlbridge.IBridgeCallback
import android.content.ComponentName
import android.content.ServiceConnection
import android.os.IBinder
class ServiceConnection: IBridgeCallback.Stub(), ServiceConnection {
override fun onServiceConnected(
name: ComponentName?,
service: IBinder?
) {
}
override fun onServiceDisconnected(name: ComponentName?) {
}
}