Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/jaino/#128
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Aug 24, 2024
2 parents 5689c4b + 9818575 commit c91043c
Show file tree
Hide file tree
Showing 22 changed files with 365 additions and 162 deletions.
43 changes: 21 additions & 22 deletions app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.bff.wespot
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -138,6 +136,7 @@ private val bottomBarScreenNames = listOf(
private val topBarScreenNames = listOf(
"vote/vote_home_screen",
"message/message_screen?isMessageSent={isMessageSent}&type={type}&messageId={messageId}",
"entire/entire_screen",
)

fun NavDestination.navGraph(): NavGraphSpec {
Expand All @@ -152,14 +151,24 @@ fun NavDestination.navGraph(): NavGraphSpec {
throw ClassNotFoundException("Unknown nav graph for destination $route")
}

internal fun NavDestination.checkDestination(position: NavigationBarPosition): Boolean {
val screenNames = when (position) {
NavigationBarPosition.BOTTOM -> bottomBarScreenNames
NavigationBarPosition.TOP -> topBarScreenNames
}

return hierarchy.any { destination ->
screenNames.any { name -> destination.route == name }
internal fun NavDestination.checkDestination(position: NavigationBarPosition): BarType {
return when (position) {
NavigationBarPosition.BOTTOM -> {
val result = hierarchy.any { destination ->
bottomBarScreenNames.any { name -> destination.route == name }
}
if (result) BarType.DEFAULT else BarType.NONE
}
NavigationBarPosition.TOP -> {
hierarchy.forEach { destination ->
when (destination.route) {
"entire/entire_screen" -> return BarType.ENTIRE
"vote/vote_home_screen" -> return BarType.DEFAULT
"message/message_screen?isMessageSent={isMessageSent}&type={type}&messageId={messageId}" -> return BarType.DEFAULT
}
}
BarType.NONE
}
}
}

Expand Down Expand Up @@ -215,12 +224,7 @@ private fun AnimatedContentTransitionScope<*>.defaultEnterTransition(
if (initialNavGraph.id != targetNavGraph.id) {
return fadeIn()
}
return fadeIn() + slideIntoContainer(
AnimatedContentTransitionScope.SlideDirection.Start,
animationSpec = spring(
stiffness = Spring.StiffnessMediumLow,
),
)
return fadeIn()
}

private fun AnimatedContentTransitionScope<*>.defaultExitTransition(
Expand All @@ -232,12 +236,7 @@ private fun AnimatedContentTransitionScope<*>.defaultExitTransition(
if (initialNavGraph.id != targetNavGraph.id) {
return fadeOut()
}
return fadeOut() + slideOutOfContainer(
AnimatedContentTransitionScope.SlideDirection.End,
animationSpec = spring(
stiffness = Spring.StiffnessMediumLow,
),
)
return fadeOut()
}

private val NavDestination.hostNavGraph: NavGraph
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/kotlin/com/bff/wespot/BarType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bff.wespot

enum class BarType {
DEFAULT,
ENTIRE,
NONE;
}
76 changes: 49 additions & 27 deletions app/src/main/kotlin/com/bff/wespot/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.theme.StaticTypeScale
import com.bff.wespot.designsystem.theme.WeSpotTheme
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
import com.bff.wespot.entire.screen.destinations.SettingScreenDestination
import com.bff.wespot.model.ToastState
import com.bff.wespot.model.notification.NotificationType
import com.bff.wespot.model.notification.convertNotificationType
Expand All @@ -64,10 +65,11 @@ import com.bff.wespot.navigation.util.EXTRA_DATE
import com.bff.wespot.navigation.util.EXTRA_TARGET_ID
import com.bff.wespot.navigation.util.EXTRA_TYPE
import com.bff.wespot.notification.screen.NotificationNavigator
import com.bff.wespot.ui.TopToast
import com.bff.wespot.state.MainAction
import com.bff.wespot.ui.TopToast
import com.bff.wespot.util.clickableSingle
import com.bff.wespot.viewmodel.MainViewModel
import com.ramcosta.composedestinations.dynamic.within
import com.ramcosta.composedestinations.navigation.navigate
import com.ramcosta.composedestinations.spec.NavGraphSpec
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -162,37 +164,57 @@ private fun MainScreen(
},
label = stringResource(com.bff.wespot.R.string.bottom_bar_animated_content_label),
) { targetState ->
if (targetState) {
if (targetState != BarType.NONE) {
WSTopBar(
title = "",
navigation = {
Image(
modifier = Modifier
.padding(top = 8.dp, bottom = 8.dp, start = 16.dp)
.size(width = 112.dp, height = 44.dp),
painter = painterResource(id = R.drawable.main_logo),
contentDescription = stringResource(
id = com.bff.wespot.message.R.string.wespot_logo,
),
)
},
action = {
IconButton(
modifier = Modifier.padding(end = 16.dp),
onClick = {
navController.navigateToNavGraph(
navGraph = AppNavGraphs.notification,
)
},
) {
Icon(
painter = painterResource(id = R.drawable.icn_alarm),
if (isTopNavigationScreen == BarType.DEFAULT) {
Image(
modifier = Modifier
.padding(top = 8.dp, bottom = 8.dp, start = 16.dp)
.size(width = 112.dp, height = 44.dp),
painter = painterResource(id = R.drawable.main_logo),
contentDescription = stringResource(
id = com.bff.wespot.message.R.string.notification_icon,
id = com.bff.wespot.message.R.string.wespot_logo,
),
)
}
},
action = {
if (isTopNavigationScreen == BarType.DEFAULT) {
IconButton(
modifier = Modifier.padding(end = 8.dp),
onClick = {
navController.navigateToNavGraph(
navGraph = AppNavGraphs.notification,
)
},
) {
Icon(
painter = painterResource(id = R.drawable.icn_alarm),
contentDescription = stringResource(
id = R.string.notification_icon,
),
)
}
} else if (isTopNavigationScreen == BarType.ENTIRE) {
IconButton(
modifier = Modifier.padding(end = 8.dp),
onClick = {
navController.navigate(
SettingScreenDestination within AppNavGraphs.entire,
)
},
) {
Icon(
painter = painterResource(id = R.drawable.icn_settings),
contentDescription = stringResource(
id = R.string.setting_icon,
),
)
}
}
},
)
}
}
Expand All @@ -205,7 +227,7 @@ private fun MainScreen(
},
label = stringResource(com.bff.wespot.R.string.top_bar_animated_content_label)
) { targetState ->
if (targetState) {
if (targetState == BarType.DEFAULT) {
val currentSelectedItem by navController.currentScreenAsState()
BottomNavigationTab(
selectedNavigation = currentSelectedItem,
Expand Down Expand Up @@ -301,8 +323,8 @@ private fun NavController.currentScreenAsState(): State<NavGraphSpec> {

@Stable
@Composable
private fun NavController.checkCurrentScreen(position: NavigationBarPosition): State<Boolean> {
val showBar = remember { mutableStateOf(false) }
private fun NavController.checkCurrentScreen(position: NavigationBarPosition): State<BarType> {
val showBar = remember { mutableStateOf(BarType.NONE) }

DisposableEffect(this) {
val listener = NavController.OnDestinationChangedListener { _, destination, _ ->
Expand Down
154 changes: 154 additions & 0 deletions core/ui/src/main/kotlin/com/bff/wespot/ui/AutoSizeText.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package com.bff.wespot.ui

import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.InternalFoundationTextApi
import androidx.compose.foundation.text.TextDelegate
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFontFamilyResolver
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.min
import androidx.compose.ui.unit.sp

@Composable
fun AutoSizeText(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
suggestedFontSizes: List<TextUnit> = emptyList(),
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current,
) {
AutoSizeText(
AnnotatedString(text),
modifier,
color,
suggestedFontSizes,
fontStyle,
fontWeight,
fontFamily,
letterSpacing,
textDecoration,
textAlign,
lineHeight,
overflow,
softWrap,
maxLines,
emptyMap(),
onTextLayout,
style,
)
}

@Composable
fun AutoSizeText(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
suggestedFontSizes: List<TextUnit> = emptyList(),
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
inlineContent: Map<String, InlineTextContent> = mapOf(),
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current,
) {
BoxWithConstraints(
modifier = modifier,
contentAlignment = Alignment.Center,
) {
var combinedTextStyle = (LocalTextStyle.current + style).copy(
fontSize = min(maxWidth, maxHeight).value.sp,
)

val fontSizes = suggestedFontSizes.ifEmpty {
MutableList(combinedTextStyle.fontSize.value.toInt()) {
(combinedTextStyle.fontSize.value - it).sp
}
}

var currentFontIndex = 0

while (shouldShrink(text, combinedTextStyle, maxLines)) {
combinedTextStyle =
combinedTextStyle.copy(fontSize = fontSizes[++currentFontIndex])
}

Text(
text = text,
color = color,
fontStyle = fontStyle,
fontWeight = fontWeight,
fontFamily = fontFamily,
letterSpacing = letterSpacing,
textDecoration = textDecoration,
textAlign = textAlign,
lineHeight = lineHeight,
overflow = overflow,
softWrap = softWrap,
maxLines = maxLines,
inlineContent = inlineContent,
onTextLayout = onTextLayout,
style = combinedTextStyle,
)
}
}

@OptIn(InternalFoundationTextApi::class)
@Composable
private fun BoxWithConstraintsScope.shouldShrink(
text: AnnotatedString,
textStyle: TextStyle,
maxLines: Int,
): Boolean {
val textDelegate = TextDelegate(
text = text,
style = textStyle,
maxLines = maxLines,
softWrap = true,
overflow = TextOverflow.Clip,
density = LocalDensity.current,
fontFamilyResolver = LocalFontFamilyResolver.current,
)

val textLayoutResult = textDelegate.layout(
constraints,
LocalLayoutDirection.current,
)

return textLayoutResult.hasVisualOverflow
}
Loading

0 comments on commit c91043c

Please sign in to comment.