discussions-and-proposals icon indicating copy to clipboard operation
discussions-and-proposals copied to clipboard

Create/Get Java/Objective-C Objects in JavaScript and Run Methods

Open xulihang opened this issue 3 years ago • 0 comments

Introduction

Hi there,

I am a B4X user and I am now trying to use React Native.

Since B4X compile its Basic-like language to Java/Objective-C, it is very easy to call Java/Objective-C objects using its JavaObject/NativeObject libraries like this:

Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int) As Bitmap
  Dim bo As JavaObject
  bo.InitializeStatic("android.graphics.Bitmap")
  Dim bmp As Bitmap = bo.RunMethod("createScaledBitmap", Array As Object(Original, Width, Height, False))
  Return bmp
End Sub

With the new JSI feature (https://github.com/react-native-community/discussions-and-proposals/issues/91), I wonder if it is possible to add such a feature as well.

Details

Maybe in JS, call a native object like this:

import NativeObject from 'react-native'
let activity = NativeObject.getCurrentActivity();
let display = activity.runMethod("getDisplay");
let rotation:number = display.runMethod("getRotation");

In this way, we don't need to create a dedicated native module (https://github.com/react-native-community/discussions-and-proposals/issues/40) for some functions.

Discussion points

Add a module to call native object and run its methods in JavaScript

xulihang avatar Feb 18 '22 03:02 xulihang