Title: Better documentation for extending native classes · Issue #141 · NativeScript/docs · GitHub
Open Graph Title: Better documentation for extending native classes · Issue #141 · NativeScript/docs
X Title: Better documentation for extending native classes · Issue #141 · NativeScript/docs
Description: 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 andr...
Open Graph Description: 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 doin...
X Description: 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 doin...
Opengraph URL: https://github.com/NativeScript/docs/issues/141
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Better documentation for extending native classes","articleBody":"### Is your feature request related to a problem? Please describe.\n\nI 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:\r\n\r\n```typescript\r\nlet constructorCalled = false\r\n\r\n@NativeClass\r\nclass MyButton extends android.widget.Button {\r\n constructor() {\r\n super()\r\n constructorCalled = true\r\n\r\n // necessary when extending TypeScript constructors\r\n return global.__native(this)\r\n }\r\n\r\n setEnabled(enabled: boolean): void {\r\n this.super.setEnabled(enabled)\r\n }\r\n}\r\n\r\nconst button = new MyButton(context)\r\n```\r\nThis 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?\r\n\r\nNone of this is mentioned.\n\n### Describe the solution you'd like\n\nI'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.\n\n### Describe alternatives you've considered\n\nI've searched through the docs, and searched the web too. Nothing is helpful.\n\n### Anything else?\n\n_No response_\n\n### Please accept these terms\n\n- [X] I have searched the [existing issues](https://github.com/NativeScript/NativeScript/issues) as well as [StackOverflow](https://stackoverflow.com/questions/tagged/nativescript) and this has not been posted before\n- [X] I agree to follow this project's [Code of Conduct](https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#coc)","author":{"url":"https://github.com/pianocomposer321","@type":"Person","name":"pianocomposer321"},"datePublished":"2024-04-17T17:22:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/141/docs/issues/141"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e8116cc8-bf8b-2182-c606-ea441c8670f2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C124:231E3E:36D0AC:4B8A4D:696E6FA0 |
| html-safe-nonce | c1f4596b432bd405cdc17746729a16fbdf0834b67ecb2d0d946033116354447a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTI0OjIzMUUzRTozNkQwQUM6NEI4QTREOjY5NkU2RkEwIiwidmlzaXRvcl9pZCI6Ijc2NDUzNDYyMDczNDA4NTExMDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dba874a7e2d4c8a0363e164fb463b048e3725cbf3999503d9196fc59b1141ab1 |
| hovercard-subject-tag | issue:2248926392 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/docs/141/issue_layout |
| twitter:image | https://opengraph.githubassets.com/785fa00a7af91d56b286ae9625424fbc3adafd90ec749e7faee40f3c0f0e7acd/NativeScript/docs/issues/141 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/785fa00a7af91d56b286ae9625424fbc3adafd90ec749e7faee40f3c0f0e7acd/NativeScript/docs/issues/141 |
| og:image:alt | 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 doin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pianocomposer321 |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd24262d9e4947a6c63df018b01e9a6da49caaf8259148a56a04b665d15d66b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/docs git https://github.com/NativeScript/docs.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 567462026 |
| octolytics-dimension-repository_nwo | NativeScript/docs |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 567462026 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/docs |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 307ab96ec5f21762ff6c530a60b1ef6b1e74dd5a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width