halfnelson / nativescript-source-to-jsx-def

Walk nativescript source to generate JSX types for `svelte-type-checker-vscode`
Other
4 stars 1 forks source link

Option to omit style from ViewBase for special handling by renderer #12

Closed shirakaba closed 4 years ago

shirakaba commented 4 years ago

Closes #10 and #11

shirakaba commented 4 years ago

This allows me (after a year of having to write rich types into style) to finally express types like this, making RNS feel very close to React DOM:

Screenshot 2020-04-22 at 00 32 10

halfnelson commented 4 years ago

This works for me. I think i will change the style tag to just be "string" for SN in case of what was discovered anyway, and I will consider some custom style handling like you suggest for svelteNative (eg, introduce a StyleAttributes class) down the track, then I guess we might be able to re-add.

shirakaba commented 4 years ago

@halfnelson Thank you very much!

I think it's reasonable to restrict style to string for SN, as Svelte has never used object-based styles to begin with.

I'm using a pretty trivial typing for style right now:

declare type RNSStyle = {
    [P in keyof Style]?: string | Style[P];
};

I'm impressed that the mapped type gives such good Intellisense when you hover over the relevant property (as in the screenshot, where I hover over backgroundColor.

All the flavours of NativeScript will need to at some point figure out a first-class method of handling styles and classes to reduce duplication whilst maintaining scoping; I think React Native's StyleSheet way is the best in town for a pure JS project. But as Svelte supports scoped CSS written in <style> tags, it has other avenues to consider.