Skip to content

Commit

Permalink
Add ClickDebounce to navigationIcon in AppBars
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarIlic committed Oct 11, 2023
1 parent 558f688 commit 8213308
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private fun RowScope.PrimalNavigationBarItem(
badge: Int = 0,
) {
val selected = primaryDestination == activeDestination
val clickDebounce by remember { mutableStateOf(ClickDebounce(timeoutMillis = 750L)) }
val clickDebounce by remember { mutableStateOf(ClickDebounce()) }
NavigationBarItem(
selected = selected,
onClick = { clickDebounce.processEvent(onClick) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import net.primal.android.core.compose.foundation.ClickDebounce
import net.primal.android.theme.AppTheme

@ExperimentalMaterial3Api
Expand Down Expand Up @@ -47,9 +51,10 @@ fun PrimalTopAppBar(
)
}
} else if (navigationIcon != null) {
val clickDebounce by remember { mutableStateOf(ClickDebounce()) }
AppBarIcon(
icon = navigationIcon,
onClick = onNavigationIconClick,
onClick = { clickDebounce.processEvent(onNavigationIconClick) },
)
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.primal.android.core.compose.foundation

class ClickDebounce(private val timeoutMillis: Long) {
class ClickDebounce(private val timeoutMillis: Long = 500L) {
private val now: Long get() = System.currentTimeMillis()

private var lastEventTimeInMillis: Long = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import net.primal.android.core.compose.PrimalDivider
import net.primal.android.core.compose.button.PrimalFilledButton
import net.primal.android.core.compose.button.PrimalOutlinedButton
import net.primal.android.core.compose.feed.FeedLazyColumn
import net.primal.android.core.compose.foundation.ClickDebounce
import net.primal.android.core.compose.foundation.rememberLazyListStatePagingWorkaround
import net.primal.android.core.compose.icons.PrimalIcons
import net.primal.android.core.compose.icons.primaliconpack.ArrowBack
Expand Down Expand Up @@ -303,11 +304,12 @@ fun ProfileScreen(
avatarPadding = with(density) { (maxAvatarSizePx - avatarSizePx.floatValue).toDp() },
avatarOffsetY = with(density) { (maxAvatarSizePx * 0.65f).toDp() },
navigationIcon = {
val clickDebounce by remember { mutableStateOf(ClickDebounce()) }
AppBarIcon(
icon = PrimalIcons.ArrowBack,
backgroundColor = Color.Black.copy(alpha = 0.5f),
tint = Color.White,
onClick = onClose,
onClick = { clickDebounce.processEvent(onClose) },
)
},
title = {
Expand Down

0 comments on commit 8213308

Please sign in to comment.