NativeScript/docs

Document @NativeClass and co.

rigor789 opened this issue · 2 comments

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
@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:

  • @NativeClass
  • @ObjCProtocols
  • @JavaProxy
  • @Interfaces
  • ... ?

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

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