Я использую SurfaceView для отображения контента OpenGL или Vulkan.
В этом SurfaceView у меня есть обратный вызов SurfaceCreated, который вызывается на одном из моих реактивных ранцев. создать приложение, но не в моем втором приложении.
SurfaceView выглядит следующим образом:
Код: Выделить всё
public final class VkSurfaceView extends SurfaceView {
public VkSurfaceView(Context pContext, long pViewCPtr) {
super(pContext, pViewCPtr);
setWillNotDraw(false);
SurfaceHolder sh = getHolder();
Log.i(TAG, "getHolder"+ sh.toString());
getHolder().addCallback(this);
}
/**
* This method is part of the SurfaceHolder.Callback interface.
*/
@Override
public void surfaceCreated(final SurfaceHolder pHolder) {
Log.i(TAG, "Surface will be created");
}
Код: Выделить всё
@Composable
fun MapView(
modifier: Modifier = Modifier,
onMapViewAttached: (mapView : VMEMapView) -> Unit = { }
) {
AndroidView(
modifier = modifier.fillMaxSize()
.background(Color.Transparent)
.clipToBounds(), // Occupy the max size in the Compose UI tree
factory = { context ->
VMEMapView(context,null).also {
onMapViewAttached(it)
}
},
update = {
}
)
}
Код: Выделить всё
@Composable
fun ContentView(
onMapViewCreated: (VMEMapView) -> Unit = {},
loadMapDataRequested: () -> Unit = {},
) {
MapView(
onMapViewAttached = { mapView ->
onMapViewCreated(mapView)
}
)
Box(
modifier = Modifier
) {
}
}
Но теперь у меня есть другое приложение, которое использует MapView в некоторых компонентах реактивного ранца:
Код: Выделить всё
@Composable
fun MapScreen(onMapViewAttached: (mapView : VMEMapView) -> Unit = { }) {
MapView(
onMapViewAttached = { mapView ->
onMapViewAttached(mapView)
}
)
}
@Composable
private fun ScaffoldContent(
navController: NavHostController,
scope: CoroutineScope,
drawerState: DrawerState,
bottomBar: @Composable () -> Unit
) {
Scaffold(
bottomBar = {
bottomBar()
},
floatingActionButton = {
ExtendedFloatingActionButton(
text = { },
icon = { Icon(Icons.Filled.Add, contentDescription = "") },
onClick = {
scope.launch {
drawerState.apply {
if (isClosed) open() else close()
}
}
}
)
}
)
{ contentPadding ->
// Screen content
Box(modifier = Modifier.padding(contentPadding)) {
NavHost(navController = navController, startDestination = "home") {
composable("home") { HomeScreen() }
composable("map") {
Box(
modifier = Modifier
.background(Color.Yellow)
.padding(32.dp)
) {
MapScreen(
onMapViewAttached = { mapView ->
viewModel.loadMapView(this@MainActivity, mapView)
}
)
}
}
composable("search") { SearchScreen() }
composable("settings") { SettingsScreen() }
}
}
}
}
Код: Выделить всё
@Composable
fun MapView(
modifier: Modifier = Modifier,
onMapViewAttached: (mapView : VMEMapView) -> Unit = { }
) {
AndroidView(
modifier = modifier.fillMaxSize()
.background(Color.Green)
.clipToBounds(), // Occupy the max size in the Compose UI tree
factory = { context ->
VMEMapView(context, attributeSet = null).also {
onMapViewAttached(it)
}
},
update = { view ->
}
)
}
Спасибо!
Я пытался установить размер, но у меня все еще есть та же проблема.
Подробнее здесь: https://stackoverflow.com/questions/793 ... -component
Мобильная версия