-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revamp the "Market" page #41
Changes from 24 commits
582ac6d
5bff148
9172856
0b4b660
af02be1
c7d10c6
8975fca
0d7409f
200cb12
7cf32c8
9bee684
912ba76
5fb683e
dd43aa7
a5d10c4
bb6370d
cc5a8d1
dd48b53
d6297c4
ef48f0c
22cfeb4
3a34825
69550aa
765b2c4
05fee62
b0dc961
ad2f175
a15193d
a8d6aeb
5e34972
8c6c4ff
c4dfaf4
d8377bd
30fdf85
88a7432
ca3c059
2f88938
ac1bad3
2d44c6f
5efbcd5
38c5ec7
97f6ac2
7d3e433
ab2e0ed
ed98a84
b698c3c
a3182fa
5343bb4
1cfbbc3
9020546
0b3ca2b
577c08c
fe90cff
947dfe0
9f3562b
f1ef868
fd1f70a
5586081
fbd4cab
e87daf0
90ca44d
5b61ccd
3de630e
7ec500a
94d3d49
6ecb1c5
2fa44ea
5d0e3ec
ed8b532
fe8f1f0
35b0bce
cc0cc3b
904b1b5
7639c08
3ff6f73
c739f69
67f2704
6bcf2b6
f77dca6
ce993ad
9a7d0a1
a380c6e
d247eee
75309be
67237d5
f09e5d4
b94bcbe
a860adc
0cb94de
8447757
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,131 @@ | ||||||
/* | ||||||
* Copyright 2023, TeamDev. All rights reserved. | ||||||
* | ||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
* you may not use this file except in compliance with the License. | ||||||
* You may obtain a copy of the License at | ||||||
* | ||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||
* | ||||||
* Redistribution and use in source and/or binary forms, with or without | ||||||
* modification, must retain the above copyright notice and the following | ||||||
* disclaimer. | ||||||
* | ||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||
*/ | ||||||
|
||||||
package io.spine.examples.shareaware.client | ||||||
|
||||||
import androidx.compose.foundation.background | ||||||
import androidx.compose.foundation.border | ||||||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||||||
import androidx.compose.foundation.interaction.collectIsFocusedAsState | ||||||
import androidx.compose.foundation.layout.Box | ||||||
import androidx.compose.foundation.layout.Row | ||||||
import androidx.compose.foundation.layout.fillMaxWidth | ||||||
import androidx.compose.foundation.layout.padding | ||||||
import androidx.compose.foundation.text.BasicTextField | ||||||
import androidx.compose.material3.MaterialTheme | ||||||
import androidx.compose.material3.Text | ||||||
import androidx.compose.runtime.Composable | ||||||
import androidx.compose.runtime.getValue | ||||||
import androidx.compose.runtime.remember | ||||||
import androidx.compose.ui.Alignment | ||||||
import androidx.compose.ui.Modifier | ||||||
import androidx.compose.ui.graphics.Color | ||||||
import androidx.compose.ui.unit.DpOffset | ||||||
import androidx.compose.ui.unit.dp | ||||||
import io.spine.examples.shareaware.client.payment.Tooltip | ||||||
|
||||||
/** | ||||||
* The input component that supports displaying a tip. | ||||||
* | ||||||
* @param value the input text to be shown in the text field | ||||||
* @param onChange the callback that is triggered when the input's value change | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @param placeholder the label to be displayed inside the input container | ||||||
* @param isError indicates if the input's current value is in error | ||||||
* @param tipMessage message to be displayed in the tooltip | ||||||
* @param containerColor the color used for the background of this input | ||||||
* @param leadingIcon the optional leading icon to be displayed at the beginning of the input field container | ||||||
*/ | ||||||
@Composable | ||||||
public fun Input( | ||||||
value: String, | ||||||
onChange: (String) -> Unit, | ||||||
placeholder: String, | ||||||
isError: Boolean, | ||||||
tipMessage: String = "", | ||||||
containerColor: Color = MaterialTheme.colorScheme.tertiary, | ||||||
leadingIcon: @Composable (() -> Unit)? = null | ||||||
) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body of this function is too long. Please extract some meaningful bits into components (preferably) or functions. |
||||||
val interactionSource = remember { MutableInteractionSource() } | ||||||
val isFocused by interactionSource.collectIsFocusedAsState() | ||||||
val borderColor = if (isFocused) MaterialTheme.colorScheme.primary else Color.Unspecified | ||||||
val toolTipIconColor = if (isError) MaterialTheme.colorScheme.error else | ||||||
MaterialTheme.colorScheme.onSecondary | ||||||
BasicTextField( | ||||||
value = value, | ||||||
onValueChange = onChange, | ||||||
textStyle = MaterialTheme.typography.bodySmall, | ||||||
interactionSource = interactionSource, | ||||||
maxLines = 1 | ||||||
) { innerTextField -> | ||||||
Row( | ||||||
modifier = Modifier | ||||||
.fillMaxWidth() | ||||||
.border( | ||||||
width = 2.dp, | ||||||
color = borderColor, | ||||||
shape = MaterialTheme.shapes.small | ||||||
) | ||||||
.background( | ||||||
color = containerColor, | ||||||
shape = MaterialTheme.shapes.small | ||||||
) | ||||||
.padding( | ||||||
start = if (leadingIcon == null) 16.dp else 5.dp, | ||||||
end = 16.dp, | ||||||
top = if (leadingIcon == null) 8.dp else 2.dp, | ||||||
bottom = if (leadingIcon == null) 8.dp else 2.dp, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's weird if |
||||||
), | ||||||
verticalAlignment = Alignment.CenterVertically, | ||||||
) { | ||||||
if (leadingIcon != null) { | ||||||
leadingIcon() | ||||||
} | ||||||
Box( | ||||||
modifier = Modifier | ||||||
.fillMaxWidth() | ||||||
.weight(1f), | ||||||
contentAlignment = Alignment.CenterStart, | ||||||
) { | ||||||
if (value.isEmpty()) { | ||||||
Text( | ||||||
text = placeholder, | ||||||
style = MaterialTheme.typography.bodySmall, | ||||||
color = MaterialTheme.colorScheme.onSecondary | ||||||
) | ||||||
} | ||||||
innerTextField() | ||||||
} | ||||||
if (tipMessage != "") { | ||||||
Tooltip( | ||||||
tip = tipMessage, | ||||||
modifier = Modifier.align(Alignment.CenterVertically), | ||||||
iconColor = toolTipIconColor, | ||||||
offset = DpOffset(130.dp, 0.dp) | ||||||
) | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to rename
stateAccessor
tobeforeObserver
(as insubscribeToEntity
) orbeforeUpdate
because it will be called every time before the state is updated with the previous state.