Skip to content

Commit 65c3791

Browse files
committed
fix(ui): ensure keyboard opens when tap anywhere on the content area
1 parent e5d03c2 commit 65c3791

File tree

8 files changed

+248
-186
lines changed

8 files changed

+248
-186
lines changed

.idea/workspace.xml

Lines changed: 9 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/opennotes/feature_node/presentation/add_edit_note/AddEditNoteScreen.kt

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.animation.core.tween
55
import androidx.compose.foundation.background
66
import androidx.compose.foundation.border
77
import androidx.compose.foundation.clickable
8+
import androidx.compose.foundation.interaction.MutableInteractionSource
89
import androidx.compose.foundation.layout.*
910
import androidx.compose.foundation.shape.CircleShape
1011
import androidx.compose.material.icons.Icons
@@ -15,6 +16,7 @@ import androidx.compose.runtime.*
1516
import androidx.compose.ui.Modifier
1617
import androidx.compose.ui.draw.clip
1718
import androidx.compose.ui.draw.shadow
19+
import androidx.compose.ui.focus.FocusRequester
1820
import androidx.compose.ui.graphics.Color
1921
import androidx.compose.ui.graphics.toArgb
2022
import androidx.compose.ui.unit.dp
@@ -43,6 +45,9 @@ fun AddEditNoteScreen(
4345
)
4446
}
4547

48+
val contentFocusRequester = remember { FocusRequester() }
49+
val titleFocusRequester = remember { FocusRequester() }
50+
4651
val scope = rememberCoroutineScope()
4752

4853
LaunchedEffect(key1 = true) {
@@ -55,6 +60,8 @@ fun AddEditNoteScreen(
5560
is AddEditNoteViewModel.UiEvent.SavedNote -> {
5661
navController.navigateUp()
5762
}
63+
64+
else -> {}
5865
}
5966
}
6067
}
@@ -99,6 +106,7 @@ fun AddEditNoteScreen(
99106
.padding(paddingValues)
100107
.padding(16.dp)
101108
) {
109+
// Color picker
102110
Row(
103111
modifier = Modifier
104112
.fillMaxWidth()
@@ -112,7 +120,7 @@ fun AddEditNoteScreen(
112120
.size(50.dp)
113121
.shadow(15.dp, CircleShape)
114122
.clip(CircleShape)
115-
.background(color = color)
123+
.background(color)
116124
.border(
117125
width = 3.dp,
118126
color = if (viewModel.noteColor.value == colorInt) Color.Black else Color.Transparent,
@@ -133,6 +141,7 @@ fun AddEditNoteScreen(
133141

134142
Spacer(modifier = Modifier.height(16.dp))
135143

144+
// Title field
136145
TransParentHintTextField(
137146
text = titleState.text,
138147
hint = titleState.hint,
@@ -142,28 +151,39 @@ fun AddEditNoteScreen(
142151
onFocusChange = {
143152
viewModel.onEvent(AddEditNoteEvent.changeTitleFocus(it))
144153
},
145-
isHintVisible = titleState.isHintVisible,
146154
singleLine = true,
147155
textStyle = MaterialTheme.typography.headlineSmall,
156+
focusRequester = titleFocusRequester,
148157
modifier = Modifier.fillMaxWidth()
149158
)
150159

151160
Spacer(modifier = Modifier.height(16.dp))
152-
153-
TransParentHintTextField(
154-
text = contentState.text,
155-
hint = contentState.hint,
156-
onValueChange = {
157-
viewModel.onEvent(AddEditNoteEvent.EnteredContent(it))
158-
},
159-
onFocusChange = {
160-
viewModel.onEvent(AddEditNoteEvent.changeContentFocus(it))
161-
},
162-
isHintVisible = contentState.isHintVisible,
163-
singleLine = false,
164-
textStyle = MaterialTheme.typography.bodyLarge,
165-
modifier = Modifier.fillMaxSize()
166-
)
161+
Box(
162+
modifier = Modifier
163+
.fillMaxWidth()
164+
.weight(1f)
165+
.clickable(
166+
interactionSource = remember { MutableInteractionSource() },
167+
indication = null
168+
) {
169+
contentFocusRequester.requestFocus()
170+
}
171+
) {
172+
TransParentHintTextField(
173+
text = contentState.text,
174+
hint = contentState.hint,
175+
onValueChange = {
176+
viewModel.onEvent(AddEditNoteEvent.EnteredContent(it))
177+
},
178+
onFocusChange = {
179+
viewModel.onEvent(AddEditNoteEvent.changeContentFocus(it))
180+
},
181+
textStyle = MaterialTheme.typography.bodyLarge,
182+
singleLine = false,
183+
focusRequester = contentFocusRequester,
184+
modifier = Modifier.fillMaxSize()
185+
)
186+
}
167187
}
168188
}
169189
}
Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
package com.opennotes.feature_node.presentation.add_edit_note.components
22

3+
import androidx.compose.foundation.interaction.MutableInteractionSource
34
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.fillMaxSize
46
import androidx.compose.foundation.layout.fillMaxWidth
7+
import androidx.compose.foundation.layout.padding
58
import androidx.compose.foundation.text.BasicTextField
69
import androidx.compose.material3.Text
710
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.remember
812
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.focus.FocusRequester
914
import androidx.compose.ui.focus.FocusState
15+
import androidx.compose.ui.focus.focusRequester
1016
import androidx.compose.ui.focus.onFocusChanged
1117
import androidx.compose.ui.graphics.Color
1218
import androidx.compose.ui.text.TextStyle
19+
import androidx.compose.ui.unit.dp
1320

1421
@Composable
1522
fun TransParentHintTextField(
1623
text: String,
1724
hint: String,
1825
modifier: Modifier = Modifier,
19-
isHintVisible: Boolean = true,
2026
onValueChange: (String) -> Unit,
2127
textStyle: TextStyle = TextStyle(),
2228
singleLine: Boolean = false,
23-
onFocusChange: (FocusState) -> Unit
29+
onFocusChange: (FocusState) -> Unit,
30+
focusRequester: FocusRequester
2431
) {
32+
val interactionSource = remember { MutableInteractionSource() }
2533

26-
Box(
34+
BasicTextField(
35+
value = text,
36+
onValueChange = onValueChange,
37+
singleLine = singleLine,
38+
textStyle = textStyle,
39+
interactionSource = interactionSource,
2740
modifier = modifier
28-
) {
29-
BasicTextField(
30-
value = text,
31-
onValueChange = onValueChange,
32-
singleLine = singleLine,
33-
textStyle = textStyle,
34-
modifier = Modifier
35-
.fillMaxWidth()
36-
.onFocusChanged {
37-
onFocusChange(it)
38-
}
39-
)
41+
.focusRequester(focusRequester)
42+
.onFocusChanged(onFocusChange),
43+
decorationBox = { innerTextField ->
44+
Box(
45+
modifier = Modifier
4046

47+
) {
48+
if (text.isEmpty()) {
49+
Text(
50+
text = hint,
51+
style = textStyle,
52+
color = Color.DarkGray,
53+
)
54+
}
4155

42-
if (isHintVisible && text.isEmpty()) {
43-
Text(text = hint, style = textStyle, color = Color.DarkGray)
56+
innerTextField()
57+
}
4458
}
45-
}
59+
)
4660
}

app/src/main/java/com/opennotes/feature_node/presentation/settings/About.kt renamed to app/src/main/java/com/opennotes/feature_node/presentation/settings/AboutScreen.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package com.opennotes.feature_node.presentation.settings
22

3-
import android.R.attr.versionCode
4-
import android.widget.Toast
53
import androidx.compose.foundation.layout.Spacer
64
import androidx.compose.foundation.layout.fillMaxSize
75
import androidx.compose.foundation.layout.height
86
import androidx.compose.foundation.layout.padding
97
import androidx.compose.foundation.lazy.LazyColumn
108
import androidx.compose.material.IconButton
119
import androidx.compose.material.icons.Icons
12-
import androidx.compose.material.icons.automirrored.filled.ArrowBack
10+
import androidx.compose.material.icons.automirrored.rounded.OpenInNew
1311
import androidx.compose.material.icons.filled.ArrowBack
1412
import androidx.compose.material.icons.filled.Download
1513
import androidx.compose.material.icons.filled.Info
16-
import androidx.compose.material.icons.filled.Language
17-
import androidx.compose.material.icons.filled.Lock
1814
import androidx.compose.material3.ExperimentalMaterial3Api
1915
import androidx.compose.material3.Icon
2016
import androidx.compose.material3.Scaffold
@@ -78,7 +74,12 @@ fun AboutScreen(navController: NavController, settingsViewModel: SettingsViewMod
7874
uriHandler.openUri("https://github.com/Fandroid745/Open-notes.git")
7975
},
8076
isLast = true,
81-
trailing = {}
77+
trailing = {
78+
Icon(
79+
imageVector = Icons.AutoMirrored.Rounded.OpenInNew,
80+
contentDescription = null
81+
)
82+
}
8283
)
8384
}
8485
}

0 commit comments

Comments
 (0)