@@ -26,13 +26,6 @@ - (instancetype)init:(RCTBridge*)_bridge {
26
26
super.translatesAutoresizingMaskIntoConstraints = false ;
27
27
super.colorPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB ;
28
28
super.depthStencilPixelFormat = MTLPixelFormatDepth32Float ;
29
-
30
- xrView = [[MTKView alloc ] initWithFrame: self .bounds device: self .device];
31
- xrView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
32
- xrView.userInteractionEnabled = false ;
33
- xrView.hidden = true ;
34
- [self addSubview: xrView];
35
- [BabylonNativeInterop updateXRView: xrView];
36
29
}
37
30
return self;
38
31
}
@@ -60,14 +53,26 @@ - (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
60
53
61
54
- (void )drawRect : (CGRect )rect {
62
55
if ([BabylonNativeInterop isXRActive ]) {
63
- xrView.hidden = false ;
64
- } else {
65
- xrView.hidden = true ;
56
+ if (!xrView) {
57
+ xrView = [[MTKView alloc ] initWithFrame: self .bounds device: self .device];
58
+ xrView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
59
+ xrView.userInteractionEnabled = false ;
60
+ [self addSubview: xrView];
61
+ [BabylonNativeInterop updateXRView: xrView];
62
+ }
63
+ } else if (xrView) {
64
+ [BabylonNativeInterop updateXRView: nil ];
65
+ [xrView removeFromSuperview ];
66
+ xrView = nil ;
66
67
}
67
68
68
69
[BabylonNativeInterop renderView ];
69
70
}
70
71
72
+ -(void )dealloc {
73
+ [BabylonNativeInterop updateXRView: nil ];
74
+ }
75
+
71
76
- (void )takeSnapshot {
72
77
// We must take the screenshot on the main thread otherwise we might fail to get a valid handle on the view's image.
73
78
dispatch_async (dispatch_get_main_queue (), ^{
0 commit comments