NativeScript / docs

The NativeScript Docs!
https://docs.nativescript.org/
12 stars 23 forks source link

Document @NativeClass and co. #12

Open rigor789 opened 1 year ago

rigor789 commented 1 year ago

From @vallemar

...how and when to use the @NativeClass or @Interface annotations, also how to add delegates in iOS. In general, how to access native under the most common situations

Example android class ```ts @NativeClass() @Interfaces([android.hardware.SensorEventListener]) class SensorEventListenerAndroid extends java.lang.Object implements android.hardware.SensorEventListener { callback: (event: number[]) => void; callbackOnAccuracyChanged: ( sensor: android.hardware.Sensor, accuracy: number ) => void; constructor(callback: (data) => void) { super(); this.callback = callback; return global.__native(this); } onAccuracyChanged(sensor: android.hardware.Sensor, accuracy: number): void { if (this.callbackOnAccuracyChanged) { this.callbackOnAccuracyChanged(sensor, accuracy); } } onSensorChanged(event: android.hardware.SensorEvent): void { if (!event || (event.values.length === 0 && event.values[0])) return; this.callback(event.values as number[]); } } export { SensorEventListenerAndroid }; ```

Document:

Eventually, we'll consolidate all of these into the @NativeClass as parameters, but until then, let's document all of these.

rigor789 commented 1 year ago

Reference: https://v6.docs.nativescript.org/core-concepts/android-runtime/binding-generator/extend-class-interface#interfaces

vallemar commented 1 year ago

I've seen some notations in plugins, like @profile, @CSSType, and @cssProperty. I'm just leaving it here to collect. I think they have nothing to do with the previous ones but well