-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* - Nav: Back button generalization * - layout improvements: consistent, better padding across screens; tested in small screen devices; BisqTextField improvements * Swipe back navigation for IOS * Fix: Back button whilte screen issue; isIOS() moved to presenter
- Loading branch information
1 parent
2c3bbe2
commit 5af44e6
Showing
17 changed files
with
247 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...in/kotlin/network/bisq/mobile/presentation/ui/components/SwipeBackIOSNavigationHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package network.bisq.mobile.presentation.ui.components | ||
|
||
import androidx.compose.foundation.gestures.detectHorizontalDragGestures | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.pointer.pointerInput | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import network.bisq.mobile.presentation.ui.AppPresenter | ||
import org.koin.compose.koinInject | ||
|
||
// TODO: | ||
// Patch work to handle horizontal swipe in iOS and pop back | ||
// Will remove this once compose officially has this support for iOS | ||
// Ref links: | ||
// - https://github.com/adrielcafe/voyager/issues/144 | ||
// - https://trycatchdebug.net/news/1426361/native-ios-swipe-back-gesture-in-compose | ||
@Composable | ||
fun SwipeBackIOSNavigationHandler( | ||
navController: NavController, | ||
content: @Composable () -> Unit | ||
) { | ||
val presenter: AppPresenter = koinInject() | ||
|
||
// TODO: Find the right way to get screenWidth in KMP way. | ||
// This is not right. | ||
val screenWidthDp = remember { 360.dp } | ||
val density = LocalDensity.current | ||
|
||
val screenWidthPx = with(density) { screenWidthDp.toPx() } | ||
val threshold = screenWidthPx / 3 | ||
|
||
var cumulativeDrag by remember { mutableStateOf(0f) } | ||
|
||
Box( | ||
modifier = if (presenter.isIOS()) { | ||
Modifier.pointerInput(Unit) { | ||
detectHorizontalDragGestures( | ||
onDragStart = { | ||
cumulativeDrag = 0f | ||
}, | ||
onDragEnd = { | ||
cumulativeDrag = 0f | ||
}, | ||
onDragCancel = { | ||
}, | ||
onHorizontalDrag = { change, dragAmount -> | ||
cumulativeDrag += dragAmount.takeIf { it > 0 } ?: 0f | ||
|
||
if (cumulativeDrag >= threshold) { | ||
if (navController.currentBackStackEntry != null) navController.popBackStack() | ||
cumulativeDrag = 0f | ||
} | ||
} | ||
) | ||
} | ||
} else { | ||
Modifier | ||
} | ||
) { | ||
content() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.