Skip to content

Commit acb85a0

Browse files
authored
Merge pull request #482 from synonymdev/feat/replace-close-with-drawer
Replace close button with drawer on TopBar
2 parents 7989bbf + ed92a70 commit acb85a0

File tree

81 files changed

+422
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+422
-477
lines changed

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 190 additions & 105 deletions
Large diffs are not rendered by default.

app/src/main/java/to/bitkit/ui/Locals.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package to.bitkit.ui
22

3+
import androidx.compose.material3.DrawerState
34
import androidx.compose.runtime.Composable
45
import androidx.compose.runtime.compositionLocalOf
56
import androidx.compose.runtime.staticCompositionLocalOf
@@ -19,6 +20,7 @@ val LocalBalances = compositionLocalOf { BalanceState() }
1920
val LocalCurrencies = compositionLocalOf { CurrencyState() }
2021

2122
// Statics
23+
val LocalDrawerState = staticCompositionLocalOf<DrawerState?> { null }
2224
val LocalAppViewModel = staticCompositionLocalOf<AppViewModel?> { null }
2325
val LocalWalletViewModel = staticCompositionLocalOf<WalletViewModel?> { null }
2426
val LocalBlocktankViewModel = staticCompositionLocalOf<BlocktankViewModel?> { null }
@@ -51,3 +53,6 @@ val settingsViewModel: SettingsViewModel?
5153

5254
val backupsViewModel: BackupsViewModel?
5355
@Composable get() = LocalBackupsViewModel.current
56+
57+
val drawerState: DrawerState?
58+
@Composable get() = LocalDrawerState.current

app/src/main/java/to/bitkit/ui/NodeInfoScreen.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import to.bitkit.ui.components.rememberMoneyText
6060
import to.bitkit.ui.components.settings.SectionHeader
6161
import to.bitkit.ui.components.settings.SettingsTextButtonRow
6262
import to.bitkit.ui.scaffold.AppTopBar
63-
import to.bitkit.ui.scaffold.CloseNavIcon
63+
import to.bitkit.ui.scaffold.DrawerNavIcon
6464
import to.bitkit.ui.scaffold.ScreenColumn
6565
import to.bitkit.ui.shared.util.clickableAlpha
6666
import to.bitkit.ui.theme.AppThemeSurface
@@ -88,7 +88,6 @@ fun NodeInfoScreen(
8888
isDevModeEnabled = isDevModeEnabled,
8989
balanceDetails = lightningState.balances,
9090
onBack = { navController.popBackStack() },
91-
onClose = { navController.navigateToHome() },
9291
onRefresh = { wallet.onPullToRefresh() },
9392
onDisconnectPeer = { wallet.disconnectPeer(it) },
9493
onCopy = { text ->
@@ -108,7 +107,6 @@ private fun Content(
108107
isDevModeEnabled: Boolean,
109108
balanceDetails: BalanceDetails? = null,
110109
onBack: () -> Unit = {},
111-
onClose: () -> Unit = {},
112110
onRefresh: () -> Unit = {},
113111
onDisconnectPeer: (PeerDetails) -> Unit = {},
114112
onCopy: (String) -> Unit = {},
@@ -117,7 +115,7 @@ private fun Content(
117115
AppTopBar(
118116
titleText = stringResource(R.string.lightning__node_info),
119117
onBackClick = onBack,
120-
actions = { CloseNavIcon(onClose) },
118+
actions = { DrawerNavIcon() },
121119
)
122120
PullToRefreshBox(
123121
isRefreshing = uiState.isRefreshing,

app/src/main/java/to/bitkit/ui/components/DrawerMenu.kt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ import androidx.compose.ui.unit.dp
3939
import androidx.compose.ui.unit.sp
4040
import androidx.compose.ui.zIndex
4141
import androidx.navigation.NavController
42+
import androidx.navigation.NavDestination.Companion.hasRoute
4243
import androidx.navigation.compose.rememberNavController
4344
import kotlinx.coroutines.launch
4445
import to.bitkit.R
4546
import to.bitkit.ui.Routes
46-
import to.bitkit.ui.navigateToSettings
47-
import to.bitkit.ui.screens.wallets.HomeRoutes
47+
import to.bitkit.ui.navigateIfNotCurrent
48+
import to.bitkit.ui.navigateToHome
4849
import to.bitkit.ui.shared.util.blockPointerInputPassthrough
4950
import to.bitkit.ui.shared.util.clickableAlpha
5051
import to.bitkit.ui.theme.AppThemeSurface
@@ -60,7 +61,6 @@ private val drawerWidth = 200.dp
6061
@Composable
6162
fun DrawerMenu(
6263
drawerState: DrawerState,
63-
walletNavController: NavController,
6464
rootNavController: NavController,
6565
hasSeenWidgetsIntro: Boolean,
6666
hasSeenShopIntro: Boolean,
@@ -96,21 +96,20 @@ fun DrawerMenu(
9696
)
9797
) {
9898
Menu(
99-
walletNavController = walletNavController,
10099
rootNavController = rootNavController,
101100
drawerState = drawerState,
102101
onClickAddWidget = {
103102
if (!hasSeenWidgetsIntro) {
104-
rootNavController.navigate(Routes.WidgetsIntro)
103+
rootNavController.navigateIfNotCurrent(Routes.WidgetsIntro)
105104
} else {
106-
rootNavController.navigate(Routes.AddWidget)
105+
rootNavController.navigateIfNotCurrent(Routes.AddWidget)
107106
}
108107
},
109108
onClickShop = {
110109
if (!hasSeenShopIntro) {
111-
rootNavController.navigate(Routes.ShopIntro)
110+
rootNavController.navigateIfNotCurrent(Routes.ShopIntro)
112111
} else {
113-
rootNavController.navigate(Routes.ShopDiscover)
112+
rootNavController.navigateIfNotCurrent(Routes.ShopDiscover)
114113
}
115114
},
116115
)
@@ -119,7 +118,6 @@ fun DrawerMenu(
119118

120119
@Composable
121120
private fun Menu(
122-
walletNavController: NavController,
123121
rootNavController: NavController,
124122
drawerState: DrawerState,
125123
onClickAddWidget: () -> Unit,
@@ -140,6 +138,11 @@ private fun Menu(
140138
label = stringResource(R.string.wallet__drawer__wallet),
141139
iconRes = R.drawable.ic_coins,
142140
onClick = {
141+
val isOnHome = rootNavController.currentBackStackEntry
142+
?.destination?.hasRoute<Routes.Home>() ?: false
143+
if (!isOnHome) {
144+
rootNavController.navigateToHome()
145+
}
143146
scope.launch { drawerState.close() }
144147
},
145148
modifier = Modifier.testTag("DrawerWallet")
@@ -149,7 +152,7 @@ private fun Menu(
149152
label = stringResource(R.string.wallet__drawer__activity),
150153
iconRes = R.drawable.ic_heartbeat,
151154
onClick = {
152-
walletNavController.navigate(HomeRoutes.AllActivity)
155+
rootNavController.navigateIfNotCurrent(Routes.AllActivity)
153156
scope.launch { drawerState.close() }
154157
},
155158
modifier = Modifier.testTag("DrawerActivity")
@@ -193,7 +196,7 @@ private fun Menu(
193196
label = stringResource(R.string.wallet__drawer__settings),
194197
iconRes = R.drawable.ic_settings,
195198
onClick = {
196-
rootNavController.navigateToSettings()
199+
rootNavController.navigateIfNotCurrent(Routes.Settings)
197200
scope.launch { drawerState.close() }
198201
},
199202
modifier = Modifier.testTag("DrawerSettings")
@@ -206,15 +209,17 @@ private fun Menu(
206209
modifier = Modifier
207210
.fillMaxWidth()
208211
.clickableAlpha {
209-
rootNavController.navigate(Routes.AppStatus)
212+
rootNavController.navigateIfNotCurrent(Routes.AppStatus)
210213
scope.launch { drawerState.close() }
211214
}
212215
) {
213216
AppStatus(
214217
showText = true,
215218
showReady = true,
216219
color = Colors.Black,
217-
modifier = Modifier.padding(vertical = 16.dp).testTag("DrawerAppStatus")
220+
modifier = Modifier
221+
.padding(vertical = 16.dp)
222+
.testTag("DrawerAppStatus")
218223
)
219224
}
220225
}
@@ -298,7 +303,6 @@ private fun Preview() {
298303
val navController = rememberNavController()
299304
Box {
300305
DrawerMenu(
301-
walletNavController = navController,
302306
rootNavController = navController,
303307
drawerState = rememberDrawerState(initialValue = DrawerValue.Open),
304308
hasSeenWidgetsIntro = false,

app/src/main/java/to/bitkit/ui/components/InfoScreenContent.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.compose.ui.tooling.preview.Preview
2121
import androidx.compose.ui.unit.dp
2222
import to.bitkit.R
2323
import to.bitkit.ui.scaffold.AppTopBar
24-
import to.bitkit.ui.scaffold.CloseNavIcon
24+
import to.bitkit.ui.scaffold.DrawerNavIcon
2525
import to.bitkit.ui.scaffold.ScreenColumn
2626
import to.bitkit.ui.theme.AppThemeSurface
2727
import to.bitkit.ui.theme.Colors
@@ -37,7 +37,6 @@ fun InfoScreenContent(
3737
showCloseButton: Boolean = true,
3838
buttonText: String,
3939
onButtonClick: () -> Unit,
40-
onCloseClick: () -> Unit,
4140
testTag: String,
4241
) {
4342
ScreenColumn {
@@ -46,7 +45,7 @@ fun InfoScreenContent(
4645
onBackClick = null,
4746
actions = {
4847
if (showCloseButton) {
49-
CloseNavIcon(onCloseClick)
48+
DrawerNavIcon()
5049
}
5150
},
5251
)
@@ -100,7 +99,6 @@ private fun Preview() {
10099
image = painterResource(R.drawable.check),
101100
buttonText = stringResource(R.string.common__ok),
102101
onButtonClick = {},
103-
onCloseClick = {},
104102
testTag = "",
105103
)
106104
}

app/src/main/java/to/bitkit/ui/scaffold/AppTopBar.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.padding
77
import androidx.compose.foundation.layout.size
88
import androidx.compose.material.icons.Icons
99
import androidx.compose.material.icons.automirrored.filled.ArrowBack
10-
import androidx.compose.material.icons.filled.Close
1110
import androidx.compose.material3.CenterAlignedTopAppBar
1211
import androidx.compose.material3.ExperimentalMaterial3Api
1312
import androidx.compose.material3.Icon
@@ -18,12 +17,15 @@ import androidx.compose.ui.Alignment
1817
import androidx.compose.ui.Modifier
1918
import androidx.compose.ui.graphics.Color
2019
import androidx.compose.ui.graphics.painter.Painter
20+
import androidx.compose.ui.platform.LocalInspectionMode
2121
import androidx.compose.ui.platform.testTag
2222
import androidx.compose.ui.res.painterResource
2323
import androidx.compose.ui.res.stringResource
2424
import androidx.compose.ui.tooling.preview.Preview
2525
import androidx.compose.ui.unit.dp
26+
import kotlinx.coroutines.launch
2627
import to.bitkit.R
28+
import to.bitkit.ui.LocalDrawerState
2729
import to.bitkit.ui.components.Title
2830
import to.bitkit.ui.theme.AppThemeSurface
2931

@@ -89,19 +91,24 @@ fun BackNavIcon(
8991
}
9092

9193
@Composable
92-
fun CloseNavIcon(
93-
onClick: () -> Unit,
94+
fun DrawerNavIcon(
9495
modifier: Modifier = Modifier,
9596
) {
96-
IconButton(
97-
onClick = onClick,
98-
modifier = modifier.testTag("NavigationClose")
99-
) {
100-
Icon(
101-
imageVector = Icons.Default.Close,
102-
contentDescription = stringResource(R.string.common__close),
103-
modifier = Modifier.size(24.dp)
104-
)
97+
val isPreview = LocalInspectionMode.current
98+
val drawerState = LocalDrawerState.current
99+
val scope = androidx.compose.runtime.rememberCoroutineScope()
100+
101+
if (drawerState != null || isPreview) {
102+
IconButton(
103+
onClick = { scope.launch { drawerState?.open() } },
104+
modifier = modifier.testTag("HeaderMenu")
105+
) {
106+
Icon(
107+
painter = painterResource(id = R.drawable.ic_list),
108+
contentDescription = stringResource(R.string.settings__settings),
109+
modifier = Modifier.size(24.dp)
110+
)
111+
}
105112
}
106113
}
107114

@@ -153,7 +160,7 @@ private fun Preview3() {
153160
titleText = "Title and Action",
154161
onBackClick = {},
155162
actions = {
156-
CloseNavIcon(onClick = {})
163+
DrawerNavIcon()
157164
}
158165
)
159166
}

app/src/main/java/to/bitkit/ui/screens/profile/CreateProfileScreen.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ import androidx.compose.ui.unit.dp
1111
import to.bitkit.R
1212
import to.bitkit.ui.components.Display
1313
import to.bitkit.ui.scaffold.AppTopBar
14-
import to.bitkit.ui.scaffold.CloseNavIcon
14+
import to.bitkit.ui.scaffold.DrawerNavIcon
1515
import to.bitkit.ui.scaffold.ScreenColumn
1616
import to.bitkit.ui.theme.AppThemeSurface
1717
import to.bitkit.ui.theme.Colors
1818

1919
@Composable
2020
fun CreateProfileScreen(
21-
onClose: () -> Unit,
2221
onBack: () -> Unit,
2322
) { // TODO IMPLEMENT
2423
ScreenColumn {
2524
AppTopBar(
2625
titleText = stringResource(R.string.slashtags__profile_create),
2726
onBackClick = onBack,
28-
actions = { CloseNavIcon(onClick = onClose) },
27+
actions = { DrawerNavIcon() },
2928
)
3029

3130
Column(
@@ -47,7 +46,6 @@ fun CreateProfileScreen(
4746
private fun Preview() {
4847
AppThemeSurface {
4948
CreateProfileScreen(
50-
onClose = {},
5149
onBack = {},
5250
)
5351
}

app/src/main/java/to/bitkit/ui/screens/profile/ProfileIntroScreen.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ import to.bitkit.ui.components.BodyM
1717
import to.bitkit.ui.components.Display
1818
import to.bitkit.ui.components.PrimaryButton
1919
import to.bitkit.ui.scaffold.AppTopBar
20-
import to.bitkit.ui.scaffold.CloseNavIcon
20+
import to.bitkit.ui.scaffold.DrawerNavIcon
2121
import to.bitkit.ui.scaffold.ScreenColumn
2222
import to.bitkit.ui.theme.AppThemeSurface
2323
import to.bitkit.ui.theme.Colors
2424
import to.bitkit.ui.utils.withAccent
2525

2626
@Composable
2727
fun ProfileIntroScreen(
28-
onClose: () -> Unit,
2928
onContinue: () -> Unit,
3029
) {
3130
ScreenColumn {
3231
AppTopBar(
3332
titleText = stringResource(R.string.slashtags__profile),
3433
onBackClick = null,
35-
actions = { CloseNavIcon(onClick = onClose) },
34+
actions = { DrawerNavIcon() },
3635
)
3736

3837
Column(
@@ -69,7 +68,6 @@ fun ProfileIntroScreen(
6968
private fun Preview() {
7069
AppThemeSurface {
7170
ProfileIntroScreen(
72-
onClose = {},
7371
onContinue = {}
7472
)
7573
}

app/src/main/java/to/bitkit/ui/screens/settings/DevSettingsScreen.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import to.bitkit.ui.appViewModel
2121
import to.bitkit.ui.components.settings.SectionHeader
2222
import to.bitkit.ui.components.settings.SettingsButtonRow
2323
import to.bitkit.ui.components.settings.SettingsTextButtonRow
24-
import to.bitkit.ui.navigateToHome
2524
import to.bitkit.ui.scaffold.AppTopBar
26-
import to.bitkit.ui.scaffold.CloseNavIcon
25+
import to.bitkit.ui.scaffold.DrawerNavIcon
2726
import to.bitkit.ui.scaffold.ScreenColumn
2827
import to.bitkit.ui.settingsViewModel
2928
import to.bitkit.ui.shared.util.shareZipFile
@@ -43,7 +42,7 @@ fun DevSettingsScreen(
4342
AppTopBar(
4443
titleText = stringResource(R.string.settings__dev_title),
4544
onBackClick = { navController.popBackStack() },
46-
actions = { CloseNavIcon(onClick = { navController.navigateToHome() }) },
45+
actions = { DrawerNavIcon() },
4746
)
4847
Column(
4948
modifier = Modifier

app/src/main/java/to/bitkit/ui/screens/settings/FeeSettingsScreen.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import com.synonym.bitkitcore.FeeRates
1818
import to.bitkit.R
1919
import to.bitkit.ui.components.settings.SectionHeader
2020
import to.bitkit.ui.components.settings.SettingsTextButtonRow
21-
import to.bitkit.ui.navigateToHome
2221
import to.bitkit.ui.scaffold.AppTopBar
23-
import to.bitkit.ui.scaffold.CloseNavIcon
22+
import to.bitkit.ui.scaffold.DrawerNavIcon
2423
import to.bitkit.ui.scaffold.ScreenColumn
2524
import to.bitkit.ui.theme.AppThemeSurface
2625
import to.bitkit.viewmodels.FeeSettingsUiState
@@ -40,21 +39,19 @@ fun FeeSettingsScreen(
4039
Content(
4140
uiState = uiState,
4241
onBack = { navController.popBackStack() },
43-
onClose = { navController.navigateToHome() },
4442
)
4543
}
4644

4745
@Composable
4846
private fun Content(
4947
uiState: FeeSettingsUiState,
5048
onBack: () -> Unit = {},
51-
onClose: () -> Unit = {},
5249
) {
5350
ScreenColumn {
5451
AppTopBar(
5552
titleText = "Fee Settings",
5653
onBackClick = onBack,
57-
actions = { CloseNavIcon(onClick = onClose) },
54+
actions = { DrawerNavIcon() },
5855
)
5956

6057
Column(

0 commit comments

Comments
 (0)