@@ -18,32 +18,27 @@ package com.example.xr.scenecore
1818
1919import androidx.xr.runtime.Session
2020import androidx.xr.runtime.math.FloatSize3d
21- import androidx.xr.scenecore.Entity
2221import androidx.xr.scenecore.ResizableComponent
23- import androidx.xr.scenecore.ResizeListener
22+ import androidx.xr.scenecore.ResizeEvent
2423import androidx.xr.scenecore.SurfaceEntity
2524import java.util.concurrent.Executor
2625
2726@Suppress(" RestrictedApi" ) // b/416066566
28- private fun resizableComponentExample (session : Session , entity : Entity , executor : Executor ) {
27+ private fun resizableComponentExample (
28+ session : Session ,
29+ surfaceEntity : SurfaceEntity ,
30+ executor : Executor
31+ ) {
2932 // [START androidxr_scenecore_resizableComponentExample]
30- val resizableComponent = ResizableComponent .create(session)
31- resizableComponent.minimumSize = FloatSize3d (177f , 100f , 1f )
33+ val resizableComponent = ResizableComponent .create(session) { event ->
34+ if (event.resizeState == ResizeEvent .ResizeState .RESIZE_STATE_END ) {
35+ // update the Entity to reflect the new size
36+ surfaceEntity.canvasShape = SurfaceEntity .CanvasShape .Quad (event.newSize.width, event.newSize.height)
37+ }
38+ }
39+ resizableComponent.minimumEntitySize = FloatSize3d (177f , 100f , 1f )
3240 resizableComponent.fixedAspectRatio = 16f / 9f // Specify a 16:9 aspect ratio
3341
34- resizableComponent.addResizeListener(
35- executor,
36- object : ResizeListener {
37- override fun onResizeEnd (entity : Entity , finalSize : FloatSize3d ) {
38- // update the size in the component
39- resizableComponent.size = finalSize
40-
41- // update the Entity to reflect the new size
42- (entity as SurfaceEntity ).canvasShape = SurfaceEntity .CanvasShape .Quad (finalSize.width, finalSize.height)
43- }
44- },
45- )
46-
47- entity.addComponent(resizableComponent)
42+ surfaceEntity.addComponent(resizableComponent)
4843 // [END androidxr_scenecore_resizableComponentExample]
4944}
0 commit comments