@@ -29,6 +29,8 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
2929import androidx.compose.foundation.layout.*
3030import androidx.compose.foundation.rememberScrollState
3131import androidx.compose.foundation.shape.CircleShape
32+ import androidx.compose.foundation.text.selection.LocalTextSelectionColors
33+ import androidx.compose.foundation.text.selection.TextSelectionColors
3234import androidx.compose.foundation.verticalScroll
3335import androidx.compose.material.icons.Icons
3436import androidx.compose.material.icons.automirrored.filled.ArrowBack
@@ -135,7 +137,6 @@ fun AddEditNoteScreen(
135137 tint = contentColor
136138 )
137139 }
138-
139140 IconButton (onClick = { viewModel.onEvent(AddEditNoteEvent .SaveNote ) }) {
140141 Icon (
141142 imageVector = Icons .Default .Done ,
@@ -150,105 +151,129 @@ fun AddEditNoteScreen(
150151 )
151152 }
152153 ) { paddingValues ->
153- Column (
154- modifier = Modifier
155- .fillMaxSize()
156- .background(backgroundColor)
157- .padding(paddingValues)
158- .imePadding()
159- .padding(16 .dp)
154+ CompositionLocalProvider (
155+ LocalContentColor provides contentColor,
156+ LocalTextSelectionColors provides TextSelectionColors (
157+ handleColor = contentColor,
158+ backgroundColor = contentColor.copy(alpha = 0.4f )
159+ )
160160 ) {
161- // Color picker
162- Row (
161+ Column (
163162 modifier = Modifier
164- .fillMaxWidth()
165- .padding(vertical = 8 .dp),
166- horizontalArrangement = Arrangement .SpaceBetween
163+ .fillMaxSize()
164+ .background(backgroundColor)
165+ .padding(paddingValues)
166+ .imePadding()
167+ .padding(16 .dp)
167168 ) {
168- noteColors.forEach { color ->
169- val colorInt = remember(color) { color.toArgb() }
170- Box (
171- modifier = Modifier
172- .size(50 .dp)
173- .shadow(15 .dp, CircleShape )
174- .clip(CircleShape )
175- .background(color)
176- .border(
177- width = 3 .dp,
178- color = if (viewModel.noteColor.value == colorInt) Color .Black else Color .Transparent ,
179- shape = CircleShape
180- )
181- .clickable {
182- scope.launch {
183- noteBackgroundAnimatable.animateTo(
184- targetValue = Color (colorInt),
185- animationSpec = tween(durationMillis = 500 )
186- )
169+
170+
171+ // Color picker
172+ Row (
173+ modifier = Modifier
174+ .fillMaxWidth()
175+ .padding(vertical = 8 .dp),
176+ horizontalArrangement = Arrangement .SpaceBetween
177+ ) {
178+ noteColors.forEach { color ->
179+ val colorInt = remember(color) { color.toArgb() }
180+ Box (
181+ modifier = Modifier
182+ .size(50 .dp)
183+ .shadow(15 .dp, CircleShape )
184+ .clip(CircleShape )
185+ .background(color)
186+ .border(
187+ width = 3 .dp,
188+ color = if (viewModel.noteColor.value == colorInt) Color .Black else Color .Transparent ,
189+ shape = CircleShape
190+ )
191+ .clickable {
192+ scope.launch {
193+ noteBackgroundAnimatable.animateTo(
194+ targetValue = Color (colorInt),
195+ animationSpec = tween(durationMillis = 500 )
196+ )
197+ }
198+ viewModel.onEvent(AddEditNoteEvent .changeColor(colorInt))
187199 }
188- viewModel.onEvent(AddEditNoteEvent .changeColor(colorInt))
189- }
190- )
200+ )
201+ }
191202 }
192- }
193203
194- Spacer (modifier = Modifier .height(16 .dp))
195204
196- TransParentHintTextField (
197- text = titleState.text,
198- hint = titleState.hint,
199- onValueChange = { viewModel.onEvent(AddEditNoteEvent .EnteredTitle (it)) },
200- onFocusChange = { viewModel.onEvent(AddEditNoteEvent .changeTitleFocus(it)) },
201- singleLine = true ,
202- textStyle = MaterialTheme .typography.headlineSmall.copy(color = contentColor),
203- focusRequester = titleFocusRequester,
204- modifier = Modifier .fillMaxWidth()
205- )
206205
207- Spacer (modifier = Modifier .height(16 .dp))
206+ Spacer (modifier = Modifier .height(16 .dp))
208207
209- Box (
210- modifier = Modifier
211- .fillMaxWidth()
212- .weight(1f )
213- ) {
214- if (isPreviewMode) {
215- MarkdownText (
216- radius = 8 ,
217- markdown = contentState.text.ifBlank { " No content to preview" },
218- isPreview = false ,
219- isEnabled = true ,
220- modifier = Modifier
221- .fillMaxSize()
222- .padding(8 .dp),
223- onContentChange = {},
224- settingsViewModel = null ,
225- textColor = contentColor
226- )
227- } else {
228- val scrollState = rememberScrollState()
229- Box (
230- modifier = Modifier
231- .fillMaxSize()
232- .verticalScroll(scrollState)
233- .clickable(
234- interactionSource = interactionSource,
235- indication = null
236- ) {
237- contentFocusRequester.requestFocus()
238- }
239- ) {
240- TransParentHintTextField (
241- text = contentState.text,
242- hint = contentState.hint,
243- onValueChange = { viewModel.onEvent(AddEditNoteEvent .EnteredContent (it)) },
244- onFocusChange = { viewModel.onEvent(AddEditNoteEvent .changeContentFocus(it)) },
245- textStyle = MaterialTheme .typography.bodyLarge.copy(color = contentColor),
246- singleLine = false ,
247- focusRequester = contentFocusRequester,
208+ TransParentHintTextField (
209+ text = titleState.text,
210+ hint = titleState.hint,
211+ onValueChange = { viewModel.onEvent(AddEditNoteEvent .EnteredTitle (it)) },
212+ onFocusChange = { viewModel.onEvent(AddEditNoteEvent .changeTitleFocus(it)) },
213+ singleLine = true ,
214+ textStyle = MaterialTheme .typography.headlineSmall.copy(color = contentColor),
215+ focusRequester = titleFocusRequester,
216+ modifier = Modifier .fillMaxWidth()
217+ )
218+
219+ Spacer (modifier = Modifier .height(16 .dp))
220+
221+ Box (
222+ modifier = Modifier
223+ .fillMaxWidth()
224+ .weight(1f )
225+ ) {
226+ if (isPreviewMode) {
227+ MarkdownText (
228+ radius = 8 ,
229+ markdown = contentState.text.ifBlank { " No content to preview" },
230+ isPreview = false ,
231+ isEnabled = true ,
248232 modifier = Modifier
249- .fillMaxWidth()
250- .wrapContentHeight(unbounded = true )
233+ .fillMaxSize()
234+ .padding(8 .dp),
235+ onContentChange = {},
236+ settingsViewModel = null ,
237+ textColor = contentColor
251238 )
239+ } else {
240+ val scrollState = rememberScrollState()
241+ Box (
242+ modifier = Modifier
243+ .fillMaxSize()
244+ .verticalScroll(scrollState)
245+ .clickable(
246+ interactionSource = interactionSource,
247+ indication = null
248+ ) {
249+ contentFocusRequester.requestFocus()
250+ }
251+ ) {
252+ TransParentHintTextField (
253+ text = contentState.text,
254+ hint = contentState.hint,
255+ onValueChange = {
256+ viewModel.onEvent(
257+ AddEditNoteEvent .EnteredContent (
258+ it
259+ )
260+ )
261+ },
262+ onFocusChange = {
263+ viewModel.onEvent(
264+ AddEditNoteEvent .changeContentFocus(
265+ it
266+ )
267+ )
268+ },
269+ textStyle = MaterialTheme .typography.bodyLarge.copy(color = contentColor),
270+ singleLine = false ,
271+ focusRequester = contentFocusRequester,
272+ modifier = Modifier
273+ .fillMaxWidth()
274+ .wrapContentHeight(unbounded = true )
275+ )
276+ }
252277 }
253278 }
254279 }
0 commit comments