Skip to content

Commit

Permalink
✨ 웹뷰 컴포넌트 생성 및 개인정보처리방침 url 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-j0y committed Nov 17, 2024
1 parent d31b10e commit 1bb342e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whyranoid.presentation.screens

import android.util.Log
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawingPadding
Expand Down Expand Up @@ -253,6 +254,14 @@ fun AppScreenContent(
}
)
}

composable(
route = Screen.WebViewScreen.route,
arguments = Screen.WebViewScreen.arguments,
) {
val url = it.arguments?.getString("url")
WebViewScreen(url = url)
}
}

val isLoading = ApiResponseDialog.isLoading.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.navigation.NamedNavArgument
import androidx.navigation.NavType
import androidx.navigation.navArgument
import com.whyranoid.presentation.R
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

sealed class Screen(
val route: String,
Expand Down Expand Up @@ -143,6 +145,21 @@ sealed class Screen(
fun route(uid: Long, postId: Long) = "userPostsScreen/$uid/$postId"
}

object WebViewScreen : Screen(
route = "webViewScreen/{$URL}",
arguments = listOf(
navArgument(URL) {
type = NavType.StringType
nullable = true
}
),
) {
fun createRoute(url: String): String {
val encodedUrl = URLEncoder.encode(url, StandardCharsets.UTF_8.toString())
return route.replace("{$URL}", encodedUrl)
}
}

companion object {
val bottomNavigationItems = listOf(Running, Community, ChallengeMainScreen, MyPage)

Expand All @@ -151,5 +168,6 @@ sealed class Screen(
const val IS_FOLLOWING_ARGUMENT = "isFollowing"
const val PAGE_NO = "pageNo"
const val POST_ID = "postId"
const val URL = "url"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.whyranoid.presentation.screens

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.ViewGroup
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView

@SuppressLint("SetJavaScriptEnabled")
@Composable
fun WebViewScreen(
url: String?,
) {
Box(modifier = Modifier.fillMaxSize()) {
AndroidView(
factory = { context ->
WebView(context).apply {
setBackgroundColor(Color.TRANSPARENT)
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
webViewClient = WebViewClient()
settings.apply {
javaScriptEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
domStorageEnabled = true
setSupportZoom(false)
}
}
},
update = { webView ->
webView.loadUrl(url ?: "")
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -63,7 +63,11 @@ fun SettingsScreen(navHostController: NavHostController) {
TopAppBar { navHostController.popBackStack() }
ProfileSection(it) {
navHostController.navigate(Screen.EditProfileScreen.route) }
SettingsList()
SettingsList(
navigateToInAppBrowser = { url ->
navHostController.navigate(Screen.WebViewScreen.createRoute(url))
}
)
}
}
}
Expand Down Expand Up @@ -119,6 +123,8 @@ fun ProfileSection(
style = WalkieTypography.SubTitle
)

Spacer(modifier = Modifier.height(8.dp))

Text(
text = user.name,
style = WalkieTypography.Body2,
Expand Down Expand Up @@ -154,7 +160,9 @@ fun ProfileSection(
}

@Composable
fun SettingsList() {
fun SettingsList(
navigateToInAppBrowser: (url: String) -> Unit = {},
) {
Spacer(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -190,13 +198,15 @@ fun SettingsList() {
MenuItem(
text = R.string.license,
icon = R.drawable.ic_info,
onClick = {
},
onClick = { },
)

MenuItem(
text = R.string.terms_and_policy,
icon = R.drawable.ic_book,
onClick = {
navigateToInAppBrowser("https://festive-recorder-88c.notion.site/140d4d2df2e2800ca1b6f35c7a1043fc?pvs=4")
}
)

val versionName = AppVersionUtil.getVersionName(context)
Expand Down

0 comments on commit 1bb342e

Please sign in to comment.