-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f39582b
commit 2577a7a
Showing
8 changed files
with
277 additions
and
93 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
7 changes: 2 additions & 5 deletions
7
app/src/main/java/org/yrovas/linklater/ui/activity/MainActivity.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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
package org.yrovas.linklater.ui.activity | ||
|
||
import android.os.Bundle | ||
import com.ramcosta.composedestinations.generated.navgraphs.RootNavGraph | ||
import com.ramcosta.composedestinations.spec.NavHostGraphSpec | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
class MainActivity : AppActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent(RootNavGraph) | ||
} | ||
override val navGraph: NavHostGraphSpec = RootNavGraph | ||
} |
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
67 changes: 67 additions & 0 deletions
67
app/src/main/java/org/yrovas/linklater/ui/common/KeyboardRow.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,67 @@ | ||
package org.yrovas.linklater.ui.common | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.ExperimentalLayoutApi | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.ime | ||
import androidx.compose.foundation.layout.isImeVisible | ||
import androidx.compose.foundation.layout.offset | ||
import androidx.compose.foundation.layout.systemBars | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.IntOffset | ||
import androidx.compose.ui.zIndex | ||
|
||
@OptIn(ExperimentalLayoutApi::class) | ||
@Composable | ||
fun KeyboardRow(content: @Composable () -> Unit) { | ||
val isImeVisible = WindowInsets.isImeVisible | ||
val density = LocalDensity.current | ||
val offsetY = | ||
WindowInsets.ime.getBottom(density) - WindowInsets.systemBars.getBottom( | ||
density | ||
) | ||
|
||
var previousOffset by remember { mutableStateOf(0) } | ||
|
||
val isKeyboardGoingDown by remember(offsetY) { | ||
derivedStateOf { | ||
val isGoingDown = previousOffset - offsetY > 0 | ||
previousOffset = offsetY | ||
isGoingDown | ||
} | ||
} | ||
val showKeyboardRow by remember( | ||
isImeVisible, isKeyboardGoingDown, offsetY | ||
) { | ||
mutableStateOf(isImeVisible && !isKeyboardGoingDown && offsetY != 0) | ||
} | ||
|
||
if (showKeyboardRow) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.zIndex(3f), | ||
contentAlignment = Alignment.BottomStart | ||
) { | ||
Box(modifier = Modifier | ||
.offset { | ||
IntOffset(0, -offsetY) | ||
} | ||
// .height(100.dp) | ||
// .border(5.dp, colorScheme.tertiaryContainer) | ||
.fillMaxWidth()) { | ||
content() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.