2
2
3
3
import android .annotation .TargetApi ;
4
4
import android .graphics .Bitmap ;
5
- import android .graphics .Canvas ;
6
5
import android .os .Build ;
7
6
import android .os .Handler ;
8
7
import android .os .HandlerThread ;
@@ -25,6 +24,7 @@ public final class EngineView extends FrameLayout implements SurfaceHolder.Callb
25
24
private final SurfaceView primarySurfaceView ;
26
25
private final SurfaceView xrSurfaceView ;
27
26
private final EventDispatcher reactEventDispatcher ;
27
+ private Runnable renderRunnable ;
28
28
29
29
public EngineView (ReactContext reactContext ) {
30
30
super (reactContext );
@@ -57,14 +57,25 @@ public void surfaceDestroyed(SurfaceHolder holder) {
57
57
58
58
this .setOnTouchListener (this );
59
59
60
- this .setWillNotDraw (false );
61
-
62
60
this .reactEventDispatcher = reactContext .getNativeModule (UIManagerModule .class ).getEventDispatcher ();
63
61
}
64
62
65
63
@ Override
66
64
public void surfaceCreated (SurfaceHolder surfaceHolder ) {
67
- // surfaceChanged is also called when the surface is created, so just do all the handling there
65
+ this .renderRunnable = new Runnable () {
66
+ @ Override
67
+ public void run () {
68
+ if (BabylonNativeInterop .isXRActive ()) {
69
+ EngineView .this .xrSurfaceView .setVisibility (View .VISIBLE );
70
+ } else {
71
+ EngineView .this .xrSurfaceView .setVisibility (View .INVISIBLE );
72
+ }
73
+
74
+ BabylonNativeInterop .renderView ();
75
+ EngineView .this .postOnAnimation (this );
76
+ }
77
+ };
78
+ this .postOnAnimation (this .renderRunnable );
68
79
}
69
80
70
81
@ Override
@@ -74,6 +85,8 @@ public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int width, int he
74
85
75
86
@ Override
76
87
public void surfaceDestroyed (SurfaceHolder surfaceHolder ) {
88
+ this .removeCallbacks (this .renderRunnable );
89
+ this .renderRunnable = null ;
77
90
}
78
91
79
92
@ Override
@@ -82,18 +95,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
82
95
return true ;
83
96
}
84
97
85
- @ Override
86
- protected void onDraw (Canvas canvas ) {
87
- if (BabylonNativeInterop .isXRActive ()) {
88
- this .xrSurfaceView .setVisibility (View .VISIBLE );
89
- } else {
90
- this .xrSurfaceView .setVisibility (View .INVISIBLE );
91
- }
92
-
93
- BabylonNativeInterop .renderView ();
94
- invalidate ();
95
- }
96
-
97
98
@ TargetApi (24 )
98
99
public void takeSnapshot () {
99
100
// Only supported on API level 24 and up, return a blank image.
0 commit comments