@babylonjs/react-native 0.65.0-alpha.49 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/package.json +5 -5
  2. package/shared/BabylonNative.h +4 -4
  3. package/android/build.gradle +0 -173
  4. package/android/include/IXrContextARCore.h +0 -10
  5. package/android/src/main/AndroidManifest.xml +0 -4
  6. package/android/src/main/java/com/babylonreactnative/BabylonModule.java +0 -37
  7. package/android/src/main/java/com/babylonreactnative/BabylonNativeInterop.java +0 -125
  8. package/android/src/main/java/com/babylonreactnative/BabylonPackage.java +0 -21
  9. package/android/src/main/java/com/babylonreactnative/EngineView.java +0 -230
  10. package/android/src/main/java/com/babylonreactnative/EngineViewManager.java +0 -71
  11. package/android/src/main/java/com/babylonreactnative/SnapshotDataReturnedEvent.java +0 -28
  12. package/android/src/main/jniLibs/arm64-v8a/libBabylonNative.so +0 -0
  13. package/android/src/main/jniLibs/arm64-v8a/libturbomodulejsijni.so +0 -0
  14. package/android/src/main/jniLibs/armeabi-v7a/libBabylonNative.so +0 -0
  15. package/android/src/main/jniLibs/armeabi-v7a/libturbomodulejsijni.so +0 -0
  16. package/android/src/main/jniLibs/x86/libBabylonNative.so +0 -0
  17. package/android/src/main/jniLibs/x86/libturbomodulejsijni.so +0 -0
  18. package/ios/BabylonModule.mm +0 -35
  19. package/ios/BabylonNativeInterop.h +0 -14
  20. package/ios/BabylonNativeInterop.mm +0 -130
  21. package/ios/EngineViewManager.mm +0 -140
  22. package/ios/ReactNativeBabylon.xcodeproj/project.pbxproj +0 -14885
  23. package/ios/ReactNativeBabylon.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +0 -8
  24. package/ios/include/IXrContextARKit.h +0 -10
  25. package/ios/libs/libBabylonNative.a +0 -0
  26. package/ios/libs/libCanvas.a +0 -0
  27. package/ios/libs/libGenericCodeGen.a +0 -0
  28. package/ios/libs/libGraphics.a +0 -0
  29. package/ios/libs/libJsRuntime.a +0 -0
  30. package/ios/libs/libMachineIndependent.a +0 -0
  31. package/ios/libs/libNativeCapture.a +0 -0
  32. package/ios/libs/libNativeEngine.a +0 -0
  33. package/ios/libs/libNativeInput.a +0 -0
  34. package/ios/libs/libNativeOptimizations.a +0 -0
  35. package/ios/libs/libNativeTracing.a +0 -0
  36. package/ios/libs/libNativeXr.a +0 -0
  37. package/ios/libs/libOGLCompiler.a +0 -0
  38. package/ios/libs/libOSDependent.a +0 -0
  39. package/ios/libs/libSPIRV.a +0 -0
  40. package/ios/libs/libUrlLib.a +0 -0
  41. package/ios/libs/libWindow.a +0 -0
  42. package/ios/libs/libXMLHttpRequest.a +0 -0
  43. package/ios/libs/libastc-codec.a +0 -0
  44. package/ios/libs/libastc.a +0 -0
  45. package/ios/libs/libbgfx.a +0 -0
  46. package/ios/libs/libbimg.a +0 -0
  47. package/ios/libs/libbx.a +0 -0
  48. package/ios/libs/libglslang.a +0 -0
  49. package/ios/libs/libnapi.a +0 -0
  50. package/ios/libs/libspirv-cross-core.a +0 -0
  51. package/ios/libs/libspirv-cross-glsl.a +0 -0
  52. package/ios/libs/libspirv-cross-msl.a +0 -0
  53. package/ios/libs/libtinyexr.a +0 -0
  54. package/ios/libs/libxr.a +0 -0
  55. package/react-native-babylon.podspec +0 -25
@@ -1,71 +0,0 @@
1
- package com.babylonreactnative;
2
-
3
- import android.widget.FrameLayout;
4
-
5
- import androidx.annotation.NonNull;
6
- import androidx.annotation.Nullable;
7
-
8
- import com.facebook.react.bridge.ReadableArray;
9
- import com.facebook.react.common.MapBuilder;
10
- import com.facebook.react.uimanager.SimpleViewManager;
11
- import com.facebook.react.uimanager.ThemedReactContext;
12
- import com.facebook.react.uimanager.annotations.ReactProp;
13
-
14
- import java.util.Map;
15
-
16
- public final class EngineViewManager extends SimpleViewManager<EngineView> {
17
- public static final int COMMAND_TAKE_SNAPSHOT = 0;
18
- public static final String COMMAND_TAKE_SNAPSHOT_NAME = "takeSnapshot";
19
-
20
- @NonNull
21
- @Override
22
- public String getName() {
23
- return "EngineView";
24
- }
25
-
26
- @ReactProp(name = "isTransparent")
27
- public void setIsTransparent(EngineView view, Boolean isTransparent) {
28
- view.setIsTransparent(isTransparent);
29
- }
30
-
31
- @NonNull
32
- @Override
33
- protected EngineView createViewInstance(@NonNull ThemedReactContext reactContext) {
34
- return new EngineView(reactContext);
35
- }
36
-
37
- @Override
38
- public void onDropViewInstance(@NonNull EngineView view) {
39
- super.onDropViewInstance(view);
40
- // TODO: Native view specific cleanup
41
- }
42
-
43
- @Override
44
- public Map<String,Integer> getCommandsMap() {
45
- return MapBuilder.of(
46
- COMMAND_TAKE_SNAPSHOT_NAME,
47
- COMMAND_TAKE_SNAPSHOT
48
- );
49
- }
50
-
51
- @Override
52
- public void receiveCommand(final EngineView view, String commandId, ReadableArray args) {
53
- // This will be called whenever a command is sent from react-native.
54
- switch (commandId) {
55
- case COMMAND_TAKE_SNAPSHOT_NAME:
56
- view.takeSnapshot();
57
- break;
58
- default:
59
- throw new IllegalArgumentException(
60
- String.format("Invalid command %s specified for EngineView. Supported Commands: takeSnapshot", commandId));
61
- }
62
- }
63
-
64
- @Override
65
- public Map getExportedCustomDirectEventTypeConstants() {
66
- return MapBuilder.builder()
67
- .put(SnapshotDataReturnedEvent.EVENT_NAME,
68
- MapBuilder.of("registrationName", SnapshotDataReturnedEvent.EVENT_NAME))
69
- .build();
70
- }
71
- }
@@ -1,28 +0,0 @@
1
- package com.babylonreactnative;
2
-
3
- import com.facebook.react.bridge.Arguments;
4
- import com.facebook.react.bridge.WritableMap;
5
- import com.facebook.react.uimanager.events.Event;
6
- import com.facebook.react.uimanager.events.RCTEventEmitter;
7
-
8
- public class SnapshotDataReturnedEvent extends Event<SnapshotDataReturnedEvent> {
9
- public static final String EVENT_NAME = "onSnapshotDataReturned";
10
- public static final String DATA_NAME = "data";
11
- private final WritableMap payload;
12
-
13
- public SnapshotDataReturnedEvent(int viewId, String imageData) {
14
- super(viewId);
15
- this.payload = Arguments.createMap();
16
- this.payload.putString(DATA_NAME, imageData);
17
- }
18
-
19
- @Override
20
- public String getEventName() {
21
- return EVENT_NAME;
22
- }
23
-
24
- @Override
25
- public void dispatch(RCTEventEmitter rctEventEmitter) {
26
- rctEventEmitter.receiveEvent(getViewTag(), getEventName(), this.payload);
27
- }
28
- }
@@ -1,35 +0,0 @@
1
- #import "BabylonNativeInterop.h"
2
-
3
- #import <React/RCTBridgeModule.h>
4
- #import <ReactCommon/CallInvoker.h>
5
-
6
- #import <Foundation/Foundation.h>
7
-
8
- @interface RCTBridge (RCTTurboModule)
9
- - (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker;
10
- @end
11
-
12
- @interface BabylonModule : NSObject <RCTBridgeModule>
13
- @end
14
-
15
- @implementation BabylonModule
16
-
17
- RCT_EXPORT_MODULE();
18
-
19
- @synthesize bridge = _bridge;
20
-
21
- RCT_EXPORT_METHOD(initialize:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
22
- self.bridge.jsCallInvoker->invokeAsync([bridge{ self.bridge }, resolve]() {
23
- [BabylonNativeInterop initialize:bridge];
24
- resolve([NSNull null]);
25
- });
26
- }
27
-
28
- RCT_EXPORT_METHOD(resetView:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
29
- dispatch_async(dispatch_get_main_queue(), ^{
30
- [BabylonNativeInterop resetView];
31
- resolve([NSNull null]);
32
- });
33
- }
34
-
35
- @end
@@ -1,14 +0,0 @@
1
- #pragma once
2
-
3
- #import <MetalKit/MetalKit.h>
4
- #import <React/RCTBridge.h>
5
-
6
- @interface BabylonNativeInterop : NSObject
7
- + (void)initialize:(RCTBridge*)bridge;
8
- + (void)updateView:(MTKView*)mtkView;
9
- + (void)renderView;
10
- + (void)resetView;
11
- + (void)updateXRView:(MTKView*)mtkView;
12
- + (bool)isXRActive;
13
- + (void)reportTouchEvent:(MTKView*)mtkView touches:(NSSet<UITouch*>*)touches event:(UIEvent*)event;
14
- @end
@@ -1,130 +0,0 @@
1
- #import "BabylonNativeInterop.h"
2
- #import "../shared/BabylonNative.h"
3
-
4
- #import <React/RCTBridge+Private.h>
5
- #import <jsi/jsi.h>
6
- #include <ReactCommon/CallInvoker.h>
7
-
8
- #import <Foundation/Foundation.h>
9
-
10
- #import <memory>
11
-
12
- using namespace facebook;
13
-
14
- @interface RCTBridge (RCTTurboModule)
15
- - (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker;
16
- @end
17
-
18
- namespace {
19
- jsi::Runtime* GetJSIRuntime(RCTBridge* bridge) {
20
- RCTCxxBridge* cxxBridge = reinterpret_cast<RCTCxxBridge*>(bridge);
21
- return reinterpret_cast<jsi::Runtime*>(cxxBridge.runtime);
22
- }
23
- }
24
-
25
- @implementation BabylonNativeInterop
26
-
27
- static NSMutableArray* activeTouches = [NSMutableArray new];
28
-
29
- + (void)initialize:(RCTBridge*)bridge {
30
- auto jsCallInvoker{ bridge.jsCallInvoker };
31
- auto jsDispatcher{ [jsCallInvoker{ std::move(jsCallInvoker) }](std::function<void()> func)
32
- {
33
- jsCallInvoker->invokeAsync([func{ std::move(func) }]
34
- {
35
- func();
36
- });
37
- } };
38
-
39
- BabylonNative::Initialize(*GetJSIRuntime(bridge), std::move(jsDispatcher));
40
-
41
- [[NSNotificationCenter defaultCenter] removeObserver:self
42
- name:RCTBridgeWillInvalidateModulesNotification
43
- object:bridge.parentBridge];
44
-
45
- [[NSNotificationCenter defaultCenter] addObserver:self
46
- selector:@selector(onBridgeWillInvalidate:)
47
- name:RCTBridgeWillInvalidateModulesNotification
48
- object:bridge.parentBridge];
49
- }
50
-
51
- // NOTE: This happens during dev mode reload, when the JS engine is being shutdown and restarted.
52
- + (void)onBridgeWillInvalidate:(NSNotification*)notification
53
- {
54
- BabylonNative::Deinitialize();
55
- }
56
-
57
- + (void)updateView:(MTKView*)mtkView {
58
- const CGFloat scale = mtkView.contentScaleFactor;
59
- const int width = static_cast<int>(mtkView.bounds.size.width * scale);
60
- const int height = static_cast<int>(mtkView.bounds.size.height * scale);
61
- if (width != 0 && height != 0) {
62
- BabylonNative::UpdateView(mtkView, width, height);
63
- }
64
- }
65
-
66
- + (void)renderView {
67
- BabylonNative::RenderView();
68
- }
69
-
70
- + (void)resetView {
71
- BabylonNative::ResetView();
72
- }
73
-
74
- + (void)updateXRView:(MTKView*)mtkView {
75
- BabylonNative::UpdateXRView(mtkView);
76
- }
77
-
78
- + (bool)isXRActive {
79
- return BabylonNative::IsXRActive();
80
- }
81
-
82
- + (void)reportTouchEvent:(MTKView*)mtkView touches:(NSSet<UITouch*>*)touches event:(UIEvent*)event {
83
- for (UITouch* touch in touches) {
84
- if (touch.view == mtkView) {
85
- const CGFloat scale = mtkView.contentScaleFactor;
86
- const CGPoint pointerPosition = [touch locationInView:mtkView];
87
- const uint32_t x = static_cast<uint32_t>(pointerPosition.x * scale);
88
- const uint32_t y = static_cast<uint32_t>(pointerPosition.y * scale);
89
-
90
- switch (touch.phase) {
91
- case UITouchPhaseBegan: {
92
- // The activeTouches array only grows, it does not shrink (to keep indices constant since they are used as pointer ids),
93
- // so look for an unused (null) array element and reuse it if found. Otherwise, add a new entry to the array.
94
- NSUInteger pointerId = [activeTouches indexOfObject:[NSNull null]];
95
- if (pointerId != NSNotFound) {
96
- [activeTouches replaceObjectAtIndex:pointerId withObject:touch];
97
- } else {
98
- pointerId = [activeTouches count];
99
- [activeTouches addObject:touch];
100
- }
101
- BabylonNative::SetTouchButtonState(static_cast<uint32_t>(pointerId), true, x, y);
102
- break;
103
- }
104
-
105
- case UITouchPhaseMoved: {
106
- NSUInteger pointerId = [activeTouches indexOfObject:touch];
107
- if (pointerId != NSNotFound) {
108
- BabylonNative::SetTouchPosition(static_cast<uint32_t>(pointerId), x, y);
109
- }
110
- break;
111
- }
112
-
113
- case UITouchPhaseEnded:
114
- case UITouchPhaseCancelled: {
115
- NSUInteger pointerId = [activeTouches indexOfObject:touch];
116
- if (pointerId != NSNotFound) {
117
- [activeTouches replaceObjectAtIndex:pointerId withObject:[NSNull null]];
118
- BabylonNative::SetTouchButtonState(static_cast<uint32_t>(pointerId), false, x, y);
119
- }
120
- break;
121
- }
122
-
123
- default:
124
- break;
125
- }
126
- }
127
- }
128
- }
129
-
130
- @end
@@ -1,140 +0,0 @@
1
- #import "BabylonNativeInterop.h"
2
-
3
- #import <React/RCTViewManager.h>
4
- #import <React/RCTUIManager.h>
5
- #import <ReactCommon/CallInvoker.h>
6
-
7
- #import <Foundation/Foundation.h>
8
- #import <UIKit/UIKit.h>
9
- #import <MetalKit/MetalKit.h>
10
-
11
- @interface EngineView : MTKView
12
-
13
- @property (nonatomic, copy) RCTDirectEventBlock onSnapshotDataReturned;
14
- @property (nonatomic, assign) BOOL isTransparent;
15
-
16
-
17
- @end
18
-
19
- @implementation EngineView {
20
- const RCTBridge* bridge;
21
- MTKView* xrView;
22
- }
23
-
24
- - (instancetype)init:(RCTBridge*)_bridge {
25
- if (self = [super initWithFrame:CGRectZero device:MTLCreateSystemDefaultDevice()]) {
26
- bridge = _bridge;
27
- super.translatesAutoresizingMaskIntoConstraints = false;
28
- super.colorPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
29
- super.depthStencilPixelFormat = MTLPixelFormatDepth32Float;
30
- }
31
- return self;
32
- }
33
-
34
- - (void)setIsTransparentFlag:(NSNumber*)isTransparentFlag {
35
- BOOL isTransparent = [isTransparentFlag intValue] == 1;
36
- if(isTransparent){
37
- [self setOpaque:NO];
38
- } else {
39
- [self setOpaque:YES];
40
- }
41
- self.isTransparent = isTransparent;
42
- }
43
-
44
- - (void)setBounds:(CGRect)bounds {
45
- [super setBounds:bounds];
46
- [BabylonNativeInterop updateView:self];
47
- }
48
-
49
- - (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
50
- [BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
51
- }
52
-
53
- - (void)touchesMoved:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
54
- [BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
55
- }
56
-
57
- - (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
58
- [BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
59
- }
60
-
61
- - (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
62
- [BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
63
- }
64
-
65
- - (void)drawRect:(CGRect)rect {
66
- if ([BabylonNativeInterop isXRActive]) {
67
- if (!xrView) {
68
- xrView = [[MTKView alloc] initWithFrame:self.bounds device:self.device];
69
- xrView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
70
- xrView.userInteractionEnabled = false;
71
- [self addSubview:xrView];
72
- [BabylonNativeInterop updateXRView:xrView];
73
- }
74
- } else if (xrView) {
75
- [BabylonNativeInterop updateXRView:nil];
76
- [xrView removeFromSuperview];
77
- xrView = nil;
78
- }
79
-
80
- [BabylonNativeInterop renderView];
81
- }
82
-
83
- -(void)dealloc {
84
- [BabylonNativeInterop updateXRView:nil];
85
- }
86
-
87
- - (void)takeSnapshot {
88
- // We must take the screenshot on the main thread otherwise we might fail to get a valid handle on the view's image.
89
- dispatch_async(dispatch_get_main_queue(), ^{
90
- // Start the graphics context.
91
- UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES /* opaque */, 0.0f);
92
-
93
- // Draw the current state of the view into the graphics context.
94
- [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:NO];
95
-
96
- // Grab the image from the graphics context, and convert into a base64 encoded JPG.
97
- UIImage* capturedImage = UIGraphicsGetImageFromCurrentImageContext();
98
- UIGraphicsEndImageContext();
99
- NSData* jpgData = UIImageJPEGRepresentation(capturedImage, .8f);
100
- NSString* encodedData = [jpgData base64EncodedStringWithOptions:0];
101
-
102
- // Fire the onSnapshotDataReturned event if hooked up.
103
- if (self.onSnapshotDataReturned != nil) {
104
- self.onSnapshotDataReturned(@{ @"data":encodedData});
105
- }
106
- });
107
- }
108
-
109
- @end
110
-
111
-
112
- @interface EngineViewManager : RCTViewManager
113
- @end
114
-
115
- @implementation EngineViewManager
116
-
117
- RCT_CUSTOM_VIEW_PROPERTY(isTransparent, NSNumber*, EngineView){
118
- [view setIsTransparentFlag:json];
119
- }
120
-
121
- RCT_EXPORT_MODULE(EngineViewManager)
122
-
123
- RCT_EXPORT_VIEW_PROPERTY(onSnapshotDataReturned, RCTDirectEventBlock)
124
-
125
- RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber*) reactTag) {
126
- // Marshal the takeSnapshot call to the appropriate EngineView.
127
- [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber*,UIView*>* viewRegistry) {
128
- EngineView* view = (EngineView*)viewRegistry[reactTag];
129
- if (!view || ![view isKindOfClass:[EngineView class]]) {
130
- return;
131
- }
132
- [view takeSnapshot];
133
- }];
134
- }
135
-
136
- - (UIView*)view {
137
- return [[EngineView alloc] init:self.bridge];
138
- }
139
-
140
- @end