Skip to content

Commit 4cd6f3a

Browse files
committed
feat: Export RNSStyle as an interface rather than a type
1 parent 53dbbac commit 4cd6f3a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

react-nativescript/src/shared/NativeScriptJSXTypings.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@ import { ReactNode, ClassAttributes } from "react";
22
import { Observable, ViewBase, Style } from "@nativescript/core";
33
import { NSVElement } from "../nativescript-vue-next/runtime/nodes";
44

5-
export type RNSStyle = {
5+
/**
6+
* NativeScript's Style class is rather irregular. It embodies various properties used by:
7+
* - ViewBase: e.g. 'flexShrink' and 'flexGrow'; yet not 'row', nor 'column', nor 'dock', nor 'left', nor 'top'.
8+
* - View: e.g. 'height', 'width', 'scaleX' and many more.
9+
* - LayoutBase: e.g. 'paddingLeft'
10+
* - FlexboxLayout: e.g. 'flexDirection'
11+
* ... yet in most cases the typings do not fully match the implementation (the typings typically do not accept
12+
* string even though the implementation does – in fact, it's key to how NativeScript Core parses XML).
13+
*
14+
* Plugins may find need to implement new styles to NativeScript Core (e.g. as YogaLayout does, introducing
15+
* 'maxWidth' and more), so we expose RNSStyle as an interface rather than a type to allow augmentation of it.
16+
*/
17+
export type OptionalStyleAllowingString = {
618
[P in keyof Style]?: string | Style[P];
719
};
820

21+
export interface RNSStyle extends OptionalStyleAllowingString {
22+
// Extending the type as an interface allows plugins to augment it.
23+
}
24+
925
export interface NativeScriptAttributes<T extends ViewBase = ViewBase> extends ClassAttributes<NSVElement<T>> {
1026
nodeRole?: string;
1127
children?: ReactNode;

0 commit comments

Comments
 (0)