Skip to content

Commit c64e952

Browse files
feature(ui/theme): - Add a composition to implement a TRANSPARENT WebView via AndroidView (legacy support), and load the html with the three.js 3d model.
this compos can be superposed on other view and only show the 3d model(invisible background).
1 parent cf5d704 commit c64e952

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.lebaillyapp.model3dviewer.composition
2+
3+
import android.annotation.SuppressLint
4+
import android.graphics.Color
5+
import android.view.View
6+
import android.webkit.WebView
7+
import android.webkit.WebViewClient
8+
import androidx.compose.foundation.Image
9+
import androidx.compose.foundation.layout.Box
10+
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.foundation.layout.padding
12+
import androidx.compose.foundation.shape.RoundedCornerShape
13+
import androidx.compose.runtime.Composable
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.draw.clip
16+
import androidx.compose.ui.layout.ContentScale
17+
import androidx.compose.ui.res.painterResource
18+
import androidx.compose.ui.unit.dp
19+
import androidx.compose.ui.viewinterop.AndroidView
20+
import com.lebaillyapp.model3dviewer.R
21+
22+
@SuppressLint("SetJavaScriptEnabled")
23+
@Composable
24+
fun TransparentThreeDViewer(modifier: Modifier = Modifier) {
25+
Box(modifier = modifier.fillMaxSize()) {
26+
// Image de fond
27+
Image(
28+
painter = painterResource(id = R.drawable.designedbck),
29+
contentScale = ContentScale.Crop,
30+
contentDescription = "Background Image",
31+
modifier = Modifier.fillMaxSize()
32+
)
33+
// WebView avec fond transparent
34+
AndroidView(
35+
factory = { context ->
36+
WebView(context).apply {
37+
settings.javaScriptEnabled = true
38+
settings.domStorageEnabled = true
39+
settings.allowFileAccess = true
40+
settings.allowContentAccess = true
41+
settings.allowFileAccessFromFileURLs = true
42+
settings.allowUniversalAccessFromFileURLs = true
43+
webViewClient = WebViewClient()
44+
setBackgroundColor(Color.TRANSPARENT) // Rendre le fond de la WebView transparent
45+
overScrollMode = View.OVER_SCROLL_NEVER
46+
loadUrl("file:///android_asset/transparent_viewer.html")
47+
}
48+
},
49+
update = { /* Aucune mise à jour spécifique nécessaire ici pour la transparence */ },
50+
modifier = Modifier
51+
.fillMaxSize()
52+
.padding(10.dp)
53+
.clip(RoundedCornerShape(10.dp))
54+
)
55+
56+
57+
58+
59+
60+
}
61+
}

0 commit comments

Comments
 (0)