Skip to content

Commit

Permalink
feat: web view 추가 #35
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 2, 2024
1 parent 1fbbbb3 commit eee7e0b
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,51 @@ package com.easyhz.noffice.core.design_system.component.webView

import android.annotation.SuppressLint
import android.view.ViewGroup
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.easyhz.noffice.core.design_system.util.webView.nofficeWebViewClient

@SuppressLint("SetJavaScriptEnabled")
@Composable
fun NofficeWebView(
modifier: Modifier = Modifier,
webView: WebView,
url: String,
onGoBack: (Boolean) -> Unit,
onLoading: (Boolean) -> Unit
) {
AndroidView(
modifier = modifier,
factory = { WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
settings.apply {
javaScriptEnabled = true
allowFileAccess = true
allowContentAccess = true
modifier = modifier.padding(bottom = 48.dp),
factory = { view ->
webView.apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
settings.apply {
javaScriptEnabled = true
allowFileAccess = true
allowContentAccess = true
domStorageEnabled = true
mediaPlaybackRequiresUserGesture = false
cacheMode = WebSettings.LOAD_DEFAULT
textZoom = 100
}
webChromeClient = WebChromeClient()
webViewClient = nofficeWebViewClient(
canGoBack = { onGoBack(it) },
onLoading = onLoading
)
}
webViewClient = nofficeWebViewClient(onLoading)
} },
update = { it.loadUrl(url)}
},
update = {
it.loadUrl(url)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,21 @@ import android.graphics.Bitmap
import android.net.Uri
import android.webkit.URLUtil
import android.webkit.WebResourceRequest
import android.webkit.WebResourceResponse
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.webkit.WebViewAssetLoader
import java.net.URISyntaxException

fun nofficeWebViewClient(
canGoBack: (Boolean) -> Unit,
onLoading: (Boolean) -> Unit
) = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return view?.context?.handleUrl(request?.url.toString()) ?: false
}

override fun shouldInterceptRequest(
view: WebView?,
request: WebResourceRequest?
): WebResourceResponse? {
val a = WebViewAssetLoader.Builder().setHttpAllowed(true).build()
return super.shouldInterceptRequest(view, request)
}

override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
canGoBack(view?.canGoBack() ?: false)
onLoading(true)
}

Expand All @@ -45,7 +37,6 @@ private fun Context.handleUrl(url: String): Boolean {
} catch (e: Exception) {
return false
}

return when (uri.scheme) {
"intent" -> {
startSchemeIntent(url)
Expand Down
1 change: 1 addition & 0 deletions core/design-system/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@
<string name="announcement_detail_date_time">이벤트 일시</string>
<string name="announcement_detail_place">이벤트 장소</string>
<string name="announcement_detail_task_list_header">TO DO LIST</string>
<string name="announcement_detail_web_view_browser_button">기본 브라우저로 연결</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.easyhz.noffice.feature.announcement.component.detail

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.easyhz.noffice.core.design_system.R
import com.easyhz.noffice.core.design_system.extension.borderBottom
import com.easyhz.noffice.core.design_system.extension.noRippleClickable
import com.easyhz.noffice.core.design_system.extension.screenHorizonPadding
import com.easyhz.noffice.core.design_system.theme.Grey400
import com.easyhz.noffice.core.design_system.theme.Grey50
import com.easyhz.noffice.core.design_system.theme.Grey700
import com.easyhz.noffice.core.design_system.theme.SemiBold14
import com.easyhz.noffice.core.design_system.theme.White

@Stable
@Composable
internal fun PlaceBottomSheetTopBar(
modifier: Modifier = Modifier,
placeUrl: String,
onClickBack: () -> Unit,
) {
Box(
modifier = modifier
.padding(top = 8.dp)
.screenHorizonPadding()
.fillMaxWidth()
.background(White)
.height(44.dp)
.borderBottom(Grey50, 1.dp)
) {

Box(
modifier = Modifier
.align(Alignment.CenterStart)
.sizeIn(minHeight = 32.dp, minWidth = 32.dp)
.noRippleClickable { onClickBack() },
contentAlignment = Alignment.CenterStart
) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.ic_chevron_left),
contentDescription = "left",
tint = Grey400
)
}


Box(
modifier = Modifier
.align(Alignment.Center)
.widthIn(max = 300.dp)
) {
Text(
text = placeUrl,
style = SemiBold14,
color = Grey700,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.easyhz.noffice.feature.announcement.component.detail

import android.webkit.WebView
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
Expand All @@ -12,7 +13,9 @@ import com.easyhz.noffice.core.design_system.component.webView.NofficeWebView
@Composable
internal fun PlaceWebView(
modifier: Modifier = Modifier,
webView: WebView,
url: String,
onGoBack: (Boolean) -> Unit,
onLoading: (Boolean) -> Unit
) {
val state = rememberScrollState()
Expand All @@ -24,8 +27,9 @@ internal fun PlaceWebView(
) {
NofficeWebView(
url = url,
onLoading = onLoading
webView = webView,
onGoBack = onGoBack,
onLoading = onLoading,
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import com.easyhz.noffice.core.common.base.UiIntent

sealed class DetailIntent: UiIntent() {
data class InitScreen(val id: Int, val title: String): DetailIntent()
data object NavigateToUp: DetailIntent()
data object ClickPlace: DetailIntent()
data object HideBottomSheet: DetailIntent()
data class LoadWebView(val isLoading: Boolean): DetailIntent()
data object ClickOpenBrowser: DetailIntent()
data object ClickWebViewBack: DetailIntent()
data class UpdateCanGoBack(val canGoBack: Boolean): DetailIntent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package com.easyhz.noffice.feature.announcement.contract.detail
import com.easyhz.noffice.core.common.base.UiSideEffect

sealed class DetailSideEffect: UiSideEffect() {
data object NavigateToUp: DetailSideEffect()
data class OpenBrowser(val url: String): DetailSideEffect()
data object NavigateToUpInWebView: DetailSideEffect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ data class DetailState(
val isLoading: Boolean,
val isShowBottomSheet: Boolean,
val isWebViewLoading: Boolean,
val canGoBack: Boolean,
val detail: AnnouncementDetail
): UiState() {
companion object {
fun init() = DetailState(
isLoading = true,
isShowBottomSheet = false,
isWebViewLoading = true,
canGoBack = false,
detail = AnnouncementDetail(
title = "",
creationDate = "",
Expand Down Expand Up @@ -46,7 +48,7 @@ internal val DUMMY = AnnouncementDetail(
organizationProfileImage = "",
date = "2024.07.27(토) 14:02",
place = "서울 창업 허브 : 장소 이름이름이름이름..",
placeUrl = "www.naver.com",
placeUrl = "https://naver.me/IGJAhyjN",
content = """
15기 챌린저 전원이 함께 모여 작업할 수 있는 모각작 세션과 UT(User Test)가 진행됩니다.
User Test는 실제 사용자가 서비스를 테스트하며 피드백하는 중요한 과정입니다. 사용자가 주어진 작업을 완료하는 데 걸리는 시간을 관찰하는 등의 방법을 통해 사용성을 평가하고, 피드백을 받아 서비스를 더욱 더 발전시킬 수 있습니다.
Expand Down
Loading

0 comments on commit eee7e0b

Please sign in to comment.