Skip to content

Commit

Permalink
Woohoo it works!
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 21, 2024
1 parent c13472c commit eeadc42
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package/android/src/main/cpp/java-bindings/JFilamentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "JFilamentView.h"
#include "JSurfaceProvider.h"
#include "JNISharedPtr.h"

namespace margelo {

Expand All @@ -26,8 +27,8 @@ jni::local_ref<JFilamentView::jhybriddata> JFilamentView::initHybrid(jni::alias_
return makeCxxInstance(jThis, surfaceProvider);
}

const SurfaceProvider& JFilamentView::getSurfaceProvider() {
return *_surfaceProvider->cthis();
std::shared_ptr<SurfaceProvider> JFilamentView::getSurfaceProvider() {
return JNISharedPtr::make_shared_from_jni<JSurfaceProvider>(_surfaceProvider);
}

} // namespace margelo
2 changes: 1 addition & 1 deletion package/android/src/main/cpp/java-bindings/JFilamentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class JFilamentView : public jni::HybridClass<JFilamentView>, public FilamentVie
~JFilamentView();
static void registerNatives();

const SurfaceProvider& getSurfaceProvider() override;
std::shared_ptr<SurfaceProvider> getSurfaceProvider() override;

private:
friend HybridBase;
Expand Down
1 change: 1 addition & 0 deletions package/cpp/FilamentProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using namespace facebook;

void FilamentProxy::loadHybridMethods() {
registerHybridMethod("loadModel", &FilamentProxy::loadModel, this);
registerHybridMethod("findFilamentView", &FilamentProxy::findFilamentView, this);
}

} // namespace margelo
8 changes: 7 additions & 1 deletion package/cpp/FilamentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

#include "FilamentView.h"

namespace margelo {} // namespace margelo
namespace margelo {

void FilamentView::loadHybridMethods() {
registerHybridMethod("getSurfaceProvider", &FilamentView::getSurfaceProvider, this);
}

} // namespace margelo
7 changes: 5 additions & 2 deletions package/cpp/FilamentView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#include "SurfaceProvider.h"
#include <string>
#include <vector>
#include "jsi/HybridObject.h"

namespace margelo {

using namespace facebook;

class FilamentView {
class FilamentView: public HybridObject {
public:
virtual const SurfaceProvider& getSurfaceProvider() = 0;
virtual std::shared_ptr<SurfaceProvider> getSurfaceProvider() = 0;

void loadHybridMethods() override;
};

} // namespace margelo
12 changes: 10 additions & 2 deletions package/src/FilamentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class FilamentView extends React.PureComponent<FilamentViewProps> {
this.ref = React.createRef<RefType>()
}

// @ts-expect-error
private get handle(): number {
const nodeHandle = findNodeHandle(this.ref.current)
if (nodeHandle == null || nodeHandle === -1) {
Expand All @@ -28,8 +27,17 @@ export class FilamentView extends React.PureComponent<FilamentViewProps> {
return nodeHandle
}

componentDidMount() {
setTimeout(() => {
const view = FilamentProxy.findFilamentView(this.handle)
const surfaceProvider = view.getSurfaceProvider()
const surface = surfaceProvider.getSurface()
console.log('Surface Width: ' + surface.getWidth())
}, 1500)
}

/** @internal */
public render(): React.ReactNode {
return <FilamentNativeView {...this.props} />
return <FilamentNativeView ref={this.ref} {...this.props} />
}
}

0 comments on commit eeadc42

Please sign in to comment.