@@ -11,9 +11,11 @@ import androidx.compose.foundation.layout.Arrangement
1111import androidx.compose.foundation.layout.Box
1212import androidx.compose.foundation.layout.Row
1313import androidx.compose.foundation.layout.fillMaxWidth
14+ import androidx.compose.foundation.layout.height
1415import androidx.compose.foundation.layout.offset
1516import androidx.compose.foundation.layout.padding
1617import androidx.compose.foundation.layout.size
18+ import androidx.compose.foundation.layout.width
1719import androidx.compose.foundation.shape.RoundedCornerShape
1820import androidx.compose.material3.MaterialTheme
1921import androidx.compose.material3.Text
@@ -45,83 +47,110 @@ fun PostTypeSwitchButton(
4547 isLocked : Boolean = true,
4648 state : MutableState <PostType > = remember { mutableStateOf(PostType .SURVIVAL ) }
4749) {
48- val isSurvival = state.value == PostType .SURVIVAL
49- val widthMax = 138 .dp.dpToPx()
50+ // val isSurvival = state.value == PostType.SURVIVAL
51+ val widthMax = 230 .dp.dpToPx()
5052 val buttonPosition: Dp by animateDpAsState(
5153 targetValue =
52- if (isSurvival) 0 .dp else 69 .dp, animationSpec = tween(
54+ when (state.value) {
55+ PostType .SURVIVAL -> 0 .dp
56+ PostType .MISSION -> 69 .dp
57+ PostType .AI_IMAGE -> 140 .dp
58+ }, animationSpec = tween(
5359 durationMillis = 130 ,
5460 easing = LinearEasing ,
5561 ),
5662 label = " "
5763 )
5864 val survivalButtonColor: Color by animateColorAsState(
59- targetValue = if (isSurvival ) MaterialTheme .bbibbiScheme.backgroundPrimary else MaterialTheme .bbibbiScheme.gray500,
65+ targetValue = if (state.value == PostType . SURVIVAL ) MaterialTheme .bbibbiScheme.backgroundPrimary else MaterialTheme .bbibbiScheme.gray500,
6066 label = " " ,
6167 )
6268 val missionButtonColor: Color by animateColorAsState(
63- targetValue = if (isSurvival ) MaterialTheme .bbibbiScheme.gray500 else MaterialTheme .bbibbiScheme.backgroundPrimary ,
69+ targetValue = if (state.value == PostType . MISSION ) MaterialTheme .bbibbiScheme.backgroundPrimary else MaterialTheme .bbibbiScheme.gray500 ,
6470 label = " " ,
6571 )
66- Box (
67- contentAlignment = Alignment .Center ,
68- modifier = Modifier
69- .size(width = 138 .dp, height = 40 .dp)
70- .background(MaterialTheme .bbibbiScheme.backgroundHover, RoundedCornerShape (40 .dp))
71- .pointerInput(Unit ) {
72- detectTapGestures { offset ->
73- if (widthMax / 2 > offset.x) {
74- state.value = PostType .SURVIVAL
75- } else {
76- state.value = PostType .MISSION
77- }
78- Timber .d(" offset: $offset " )
79- }
80- }
81- // .padding(vertical = 8.dp, horizontal = 12.dp)
82- ) {
72+ Box {
8373 Box (
74+ contentAlignment = Alignment .CenterStart ,
8475 modifier = Modifier
85- .align(Alignment .CenterStart )
86- .offset(x = buttonPosition)
87- .size(width = 70 .dp, height = 40 .dp)
88- .background(MaterialTheme .bbibbiScheme.iconSelected, RoundedCornerShape (40 .dp))
89- )
90- Row (
91- modifier = Modifier
92- .fillMaxWidth()
93- .padding(
94- start = 24 .dp,
95- end = if (isLocked) 14 .dp else 24 .dp
96- ),
97- horizontalArrangement = Arrangement .SpaceBetween ,
76+ .size(width = 230 .dp, height = 40 .dp)
77+ .background(MaterialTheme .bbibbiScheme.backgroundHover, RoundedCornerShape (40 .dp))
78+ .pointerInput(Unit ) {
79+ detectTapGestures { offset ->
80+ val divVal = widthMax / 3
81+ if (offset.x < divVal) {
82+ state.value = PostType .SURVIVAL
83+ } else if (offset.x < divVal * 2 ) {
84+ state.value = PostType .MISSION
85+ } else {
86+ state.value = PostType .AI_IMAGE
87+ }
88+ Timber .d(" offset: $offset " )
89+ }
90+ }
9891 ) {
99- Text (
100- text = stringResource(id = R .string.post_type_survival),
101- style = MaterialTheme .bbibbiTypo.bodyTwoBold,
102- color = survivalButtonColor
92+
93+ Box (
94+ modifier = Modifier
95+ .align(Alignment .CenterStart )
96+ .offset(x = buttonPosition)
97+ .size(width = 70 .dp, height = 40 .dp)
98+ .background(MaterialTheme .bbibbiScheme.iconSelected, RoundedCornerShape (40 .dp))
10399 )
104- Row (
105- verticalAlignment = Alignment . CenterVertically ,
106- horizontalArrangement = Arrangement .spacedBy( 2 .dp)
100+ Box (
101+ modifier = Modifier .width( 138 .dp) ,
102+ contentAlignment = Alignment . CenterStart
107103 ) {
108- Text (
109- text = stringResource(id = R .string.post_type_mission),
110- style = MaterialTheme .bbibbiTypo.bodyTwoBold,
111- color = missionButtonColor,
112- )
113- if (isLocked) {
114- Image (
115- modifier = Modifier .size(12 .dp),
116- painter = painterResource(id = R .drawable.lock_icon),
117- contentDescription = " locked"
104+ Row (
105+ modifier = Modifier
106+ .width(138 .dp)
107+ .padding(
108+ start = 24 .dp,
109+ end = if (isLocked) 14 .dp else 24 .dp
110+ ),
111+ horizontalArrangement = Arrangement .SpaceBetween ,
112+ ) {
113+ Text (
114+ text = stringResource(id = R .string.post_type_survival),
115+ style = MaterialTheme .bbibbiTypo.bodyTwoBold,
116+ color = survivalButtonColor
118117 )
118+ Row (
119+ verticalAlignment = Alignment .CenterVertically ,
120+ horizontalArrangement = Arrangement .spacedBy(2 .dp)
121+ ) {
122+ Text (
123+ text = stringResource(id = R .string.post_type_mission),
124+ style = MaterialTheme .bbibbiTypo.bodyTwoBold,
125+ color = missionButtonColor,
126+ )
127+ if (isLocked) {
128+ Image (
129+ modifier = Modifier .size(12 .dp),
130+ painter = painterResource(id = R .drawable.lock_icon),
131+ contentDescription = " locked"
132+ )
133+ }
134+ }
119135 }
120136 }
121137
122138 }
139+ Box (
140+ modifier = Modifier .offset(x = 136 .dp)
141+ ) {
142+ Image (
143+ modifier = Modifier
144+ .background(Color .Transparent )
145+ .size(width = 94 .dp, height = 40 .dp),
146+ painter = painterResource(id = R .drawable.photo_studio),
147+ contentDescription = " photo studio" ,
148+ )
149+ }
150+
123151 }
124152
153+
125154}
126155
127156@Preview
0 commit comments