NativeScript / NativeScript/docs

Better documentation for extending native classes

未关闭
#141 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
JavaScript
星标
17
派生
31
平均合并
8 小时 51 分钟
30 天内合并 PR
2

描述

Is your feature request related to a problem? Please describe.

I need to have access to a native method for the ListView component. The documentation is very unclear about how I would go about doing this. It says that I can subclass android components and has a short example of what this would look like, but the example is frankly very unhelpful:

let constructorCalled = false

@NativeClass
class MyButton extends android.widget.Button {
  constructor() {
    super()
    constructorCalled = true

    // necessary when extending TypeScript constructors
    return global.__native(this)
  }

  setEnabled(enabled: boolean): void {
    this.super.setEnabled(enabled)
  }
}

const button = new MyButton(context)

This example refers to the NativeClass decorator and the android.widget.Button class. Presumeable these would have to be imported from some nativescript modules, but there are no import statements at the top of the file. Where are these coming from? Also, how do I then use this class after extending the base class? If I want it to show up in a stack layout on my main page, for example, how would I do this using nativescript? What about with Vue? Or Svelte? Just instantiating it at the bottom of the file does nothing to tell the application where it should be placed. Also, do I need to place this code in some specific file or directory for it to be picked up by the rest of my code, like from the .xml file?

None of this is mentioned.

Describe the solution you'd like

I'd be satisfied if someone could answer my questions here, but I think the documentation could benefit a lot from this information being added to it directly.

Describe alternatives you've considered

I've searched through the docs, and searched the web too. Nothing is helpful.

Anything else?

No response

Please accept these terms

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从包含 TypeScript NativeClass 和 android.widget.Button 示例的现有文档部分开始。明确 import、类的位置,以及如何在 StackLayout 中渲染一个继承的原生视图,包括 NativeScript、Vue 和 Svelte 的用法;完成的标准是页面通过完整示例回答这些问题,并解释 XML 与代码之间的关系。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, typescript
领域
documentation, mobile
Issue 类型
文档
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。