NativeScript / NativeScript/docs

Document @NativeClass and co.

Open
#12 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
17
Forks
31
Avg merge
8h 51m
Merged PRs (30d)
2

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing NativeScript documentation structure and the Android example in this issue, then identify the current guidance for @NativeClass, @ObjCProtocols, @JavaProxy, and @Interfaces. Document common Android and iOS native-access patterns, including delegates, and ensure each annotation's usage and purpose are explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, ios, typescript
Domain
documentation, mobile-dev
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.