Skip to content

Commit

Permalink
fix: Fix getting AppleFilamentView
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 22, 2024
1 parent b0c8bc6 commit 89a9090
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 108 deletions.
119 changes: 47 additions & 72 deletions package/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,49 @@ PODS:
- React-Core (= 0.73.4)
- React-jsi (= 0.73.4)
- ReactCommon/turbomodule/core (= 0.73.4)
- Filament (1.50.2):
- Filament/camutils (= 1.50.2)
- Filament/filamat (= 1.50.2)
- Filament/filament (= 1.50.2)
- Filament/filameshio (= 1.50.2)
- Filament/gltfio_core (= 1.50.2)
- Filament/image (= 1.50.2)
- Filament/ktxreader (= 1.50.2)
- Filament/math (= 1.50.2)
- Filament/tsl (= 1.50.2)
- Filament/uberz (= 1.50.2)
- Filament/utils (= 1.50.2)
- Filament/viewer (= 1.50.2)
- Filament/camutils (1.50.2):
- Filament/math
- Filament/filamat (1.50.2):
- Filament/math
- Filament/utils
- Filament/filament (1.50.2):
- Filament/math
- Filament/utils
- Filament/filameshio (1.50.2):
- Filament/filament
- Filament/gltfio_core (1.50.2):
- Filament/filament
- Filament/ktxreader
- Filament/uberz
- Filament/image (1.50.2):
- Filament/filament
- Filament/ktxreader (1.50.2):
- Filament/filament
- Filament/image
- Filament/math (1.50.2)
- Filament/tsl (1.50.2)
- Filament/uberz (1.50.2):
- Filament/filamat
- Filament/tsl
- Filament/utils
- Filament/utils (1.50.2):
- Filament/tsl
- Filament/viewer (1.50.2):
- Filament/filament
- Filament/gltfio_core
- fmt (6.2.1)
- glog (0.3.5)
- hermes-engine (0.73.4):
Expand Down Expand Up @@ -887,80 +930,10 @@ PODS:
- glog
- React-debug
- react-native-filament (0.0.1):
- Filament
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/camutils (= 0.0.1)
- react-native-filament/filamat (= 0.0.1)
- react-native-filament/filament (= 0.0.1)
- react-native-filament/filameshio (= 0.0.1)
- react-native-filament/gltfio_core (= 0.0.1)
- react-native-filament/image (= 0.0.1)
- react-native-filament/ktxreader (= 0.0.1)
- react-native-filament/math (= 0.0.1)
- react-native-filament/tsl (= 0.0.1)
- react-native-filament/uberz (= 0.0.1)
- react-native-filament/utils (= 0.0.1)
- react-native-filament/camutils (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/math
- react-native-filament/filamat (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/math
- react-native-filament/utils
- react-native-filament/filament (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/math
- react-native-filament/utils
- react-native-filament/filameshio (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-filament/gltfio_core (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-filament/ktxreader
- react-native-filament/uberz
- react-native-filament/image (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-filament/ktxreader (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filament
- react-native-filament/image
- react-native-filament/math (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/tsl (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/uberz (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/filamat
- react-native-filament/tsl
- react-native-filament/utils
- react-native-filament/utils (0.0.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- react-native-filament/tsl
- React-nativeconfig (0.73.4)
- React-NativeModulesApple (0.73.4):
- glog
Expand Down Expand Up @@ -1187,6 +1160,7 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- Filament
- fmt
- libevent
- SocketRocket
Expand Down Expand Up @@ -1297,6 +1271,7 @@ SPEC CHECKSUMS:
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
FBLazyVector: 84f6edbe225f38aebd9deaf1540a4160b1f087d7
FBReactNativeSpec: d0086a479be91c44ce4687a962956a352d2dc697
Filament: 5dd90546dd8d074ff2c03ab64cd18d06d6fab76b
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: b2669ce35fc4ac14f523b307aff8896799829fe2
Expand All @@ -1322,7 +1297,7 @@ SPEC CHECKSUMS:
React-jsinspector: 9ac353eccf6ab54d1e0a33862ba91221d1e88460
React-logger: 0a57b68dd2aec7ff738195f081f0520724b35dab
React-Mapbuffer: 63913773ed7f96b814a2521e13e6d010282096ad
react-native-filament: 83933a7e99ec2fd23c149c4a7d1b93fa559a8a3c
react-native-filament: 457f8a2d45ec68ef004c0de3357e4457abdcd9de
React-nativeconfig: d7af5bae6da70fa15ce44f045621cf99ed24087c
React-NativeModulesApple: 0123905d5699853ac68519607555a9a4f5c7b3ac
React-perflogger: 8a1e1af5733004bdd91258dcefbde21e0d1faccd
Expand Down
2 changes: 2 additions & 0 deletions package/ios/src/AppleFilamentProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2023 mrousavy. All rights reserved.
//

#pragma once

#include "FilamentProxy.h"
#include <ReactCommon/CallInvoker.h>
#include <jsi/jsi.h>
Expand Down
10 changes: 6 additions & 4 deletions package/ios/src/AppleFilamentProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <React/RCTBridge+Private.h>
#import <React/RCTUIManager.h>
#import "FilamentView.h"
#import "FilamentMetalView.h"
#import "AppleFilamentView.h"

namespace margelo {
Expand All @@ -30,14 +31,15 @@

std::shared_ptr<FilamentView> AppleFilamentProxy::findFilamentView(int viewId) {
// TODO(marc): Make this async when JSIConvert can do that
RCTUnsafeExecuteOnMainQueueSync(^{
std::shared_ptr<AppleFilamentView> result;
RCTUnsafeExecuteOnMainQueueSync([viewId, &result]() {
RCTBridge* currentBridge = [RCTBridge currentBridge]; // <-- from <React/RCTBridge+Private.h>
RCTUIManager* uiManager = currentBridge.uiManager; // <-- from <React/RCTUIManager.h>
UIView* anonymousView = [uiManager viewForReactTag:[NSNumber numberWithInt:viewId]];
AppleFilamentView* view = (AppleFilamentView*) anonymousView;
// TODO: Somehow convert the Objective-C type "AppleFilamentView" to a C++ type "FilamentView"
FilamentMetalView* view = (FilamentMetalView*) anonymousView;
result.reset(new AppleFilamentView(view));
});
throw std::runtime_error("Cannot get FilamentView on iOS yet!");
return std::static_pointer_cast<FilamentView>(result);
}


Expand Down
25 changes: 14 additions & 11 deletions package/ios/src/AppleFilamentView.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
//
// AppleFilamentView.h
// Pods
// react-native-filament
//
// Created by Marc Rousavy on 22.02.24.
//

#pragma once

#import <UIKit/UIKit.h>
#include "FilamentView.h"
#include "FilamentMetalView.h"
#include "SurfaceProvider.h"

NS_ASSUME_NONNULL_BEGIN
namespace margelo {

@interface AppleFilamentView : UIView
class AppleFilamentView : public FilamentView {
public:
explicit AppleFilamentView(FilamentMetalView* view): _view(view) {}

std::shared_ptr<SurfaceProvider> getSurfaceProvider() override;
private:
FilamentMetalView* _view;
};

- (instancetype) init;

- (CAMetalLayer*) layer;

@end

NS_ASSUME_NONNULL_END
} // namespace margelo
26 changes: 10 additions & 16 deletions package/ios/src/AppleFilamentView.mm
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
#import "AppleFilamentView.h"
#import <UIKit/UIKit.h>
#import <Metal/Metal.h>
//
// AppleFilamentView.cpp
// react-native-filament
//
// Created by Marc Rousavy on 22.02.24.
//

@implementation AppleFilamentView
#include "AppleFilamentView.h"

+ (Class) layerClass {
return [CAMetalLayer class];
}
namespace margelo {

- (CAMetalLayer*) layer {
return (CAMetalLayer*) super.layer;
std::shared_ptr<SurfaceProvider> AppleFilamentView::getSurfaceProvider() {
return nullptr;
}

- (instancetype)init {
if (self = [super init]) {
// init here
}
return self;
}

@end
2 changes: 2 additions & 0 deletions package/ios/src/FilamentInstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Marc Rousavy on 20.02.24.
//

#pragma once

#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>

Expand Down
22 changes: 22 additions & 0 deletions package/ios/src/FilamentMetalView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FilamentView.h
// Pods
//
// Created by Marc Rousavy on 22.02.24.
//

#pragma once

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface FilamentMetalView : UIView

- (instancetype) init;

- (CAMetalLayer*) layer;

@end

NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions package/ios/src/FilamentMetalView.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#import "FilamentMetalView.h"
#import <UIKit/UIKit.h>
#import <Metal/Metal.h>

@implementation FilamentMetalView

+ (Class) layerClass {
return [CAMetalLayer class];
}

- (CAMetalLayer*) layer {
return (CAMetalLayer*) super.layer;
}

- (instancetype)init {
if (self = [super init]) {
// init here
}
return self;
}

@end
2 changes: 2 additions & 0 deletions package/ios/src/FilamentModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Marc Rousavy on 22.02.24.
//

#pragma once

#import <React/RCTBridgeModule.h>

@interface FilamentModule : NSObject <RCTBridgeModule>
Expand Down
8 changes: 4 additions & 4 deletions package/ios/src/FilamentViewManager.mm
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#import <Foundation/Foundation.h>
#import <React/RCTViewManager.h>
#import "AppleFilamentView.h"
#import "FilamentMetalView.h"

@interface FilamentViewManager : RCTViewManager
@end

@implementation FilamentViewManager

RCT_EXPORT_MODULE(FilamentView)
RCT_EXPORT_MODULE(FilamentMetalView)

- (AppleFilamentView*)view {
return [[AppleFilamentView alloc] init];
- (FilamentMetalView*)view {
return [[FilamentMetalView alloc] init];
}

@end
2 changes: 1 addition & 1 deletion package/react-native-filament.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Pod::Spec.new do |s|
# Note how this does not include headers, since those can nameclash.
s.source_files = [
"cpp/**/*.{h,c,cpp}",
"ios/src/**/*.{h,m,mm}",
"ios/src/**/*.{h,m,mm,cpp}",
]

# Any private headers that are not globally unique should be mentioned here.
Expand Down

0 comments on commit 89a9090

Please sign in to comment.