shirakaba / react-nativescript

React renderer for NativeScript
https://react-nativescript.netlify.com
MIT License
280 stars 14 forks source link

Usability improvements for "style" #55

Open shirakaba opened 4 years ago

shirakaba commented 4 years ago

Should accept an array of styles (like React Native), and should not throw an error if an undefined style is passed in (because we've marked it as optional).

Should probably also be added to the typings of ViewBase so that it comes up in, e.g. FlexboxAttributes.

t1amat9409 commented 4 years ago

Funny I was looking at Styled Components and thought of a way I'd used them with RNS.

shirakaba commented 3 years ago

As for strongly-typed style objects (à la React Native's StyleSheet.create()), this seems to do the trick:

import type { RNSStyle } from "react-nativescript";

type RNSStyleSheet<T extends {}> = {
    [P in keyof T]: RNSStyle;
}
export const createStyleSheet = <T extends {}>(arg: RNSStyleSheet<T>): RNSStyleSheet<T> => arg;
shirakaba commented 3 years ago

RNS v2.2.0 now implements a provisional StyleSheet.create() API.

Accepting an array of styles is not yet supported, but now that I've fixed a styles issue, it may be not far off being implemented.