Skip to content

Commit

Permalink
Support round and TS types (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirsky authored Oct 3, 2023
1 parent f39ea6e commit 68c63b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
20 changes: 17 additions & 3 deletions extend.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as RN from "react-native";
import { StringifiedStyles, NamedStyles } from './index.d';

declare module "react-native-size-matters/extend" {
export function scale(size: number): number;
Expand All @@ -11,9 +10,24 @@ declare module "react-native-size-matters/extend" {
export function ms(size: number, factor?: number): number;
export function mvs(size: number, factor?: number): number;

type Scale = `${number}@s${'r' | ''}`;
type VerticalScale = `${number}@vs${'r' | ''}`;
type ModerateScale = `${number}@ms${number | ''}${'r' | ''}`;
type ModerateVerticalScale = `${number}@mvs${number | ''}${'r' | ''}`;
type Size = Scale | VerticalScale | ModerateScale | ModerateVerticalScale;
type WithSize<T> = { [P in keyof T]: number extends T[P] ? Size | T[P] : T[P] };
type ViewStyle = WithSize<RN.ViewStyle>;
type TextStyle = WithSize<RN.TextStyle>;
type ImageStyle = WithSize<RN.ImageStyle>;
type NamedStyles<T> = { [P in keyof T]: ViewStyle | TextStyle | ImageStyle };

export namespace ScaledSheet {
export function create<T extends NamedStyles<T> | NamedStyles<any>>(stylesObject: T): {
[P in keyof T]: RN.RegisteredStyle<T[P] & Record<Extract<keyof T[P], keyof StringifiedStyles>, number>>
export function create<T extends NamedStyles<T> | NamedStyles<any>>(
stylesObject: T,
): {
[P in keyof T]: RN.RegisteredStyle<{
[S in keyof T[P]]: T[P][S] extends Size ? number : T[P][S];
}>;
};
}
}
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ declare module 'react-native-size-matters' {
export function ms(size: number, factor?: number): number;
export function mvs(size: number, factor?: number): number;

type Scale = `${number}@s`;
type VerticalScale = `${number}@vs`;
type ModerateScale = `${number}@ms${number | ''}`;
type ModerateVerticalScale = `${number}@mvs${number | ''}`;
type Scale = `${number}@s${'r' | ''}`;
type VerticalScale = `${number}@vs${'r' | ''}`;
type ModerateScale = `${number}@ms${number | ''}${'r' | ''}`;
type ModerateVerticalScale = `${number}@mvs${number | ''}${'r' | ''}`;
type Size = Scale | VerticalScale | ModerateScale | ModerateVerticalScale;
type WithSize<T> = { [P in keyof T]: number extends T[P] ? Size | T[P] : T[P] };
type ViewStyle = WithSize<RN.ViewStyle>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-size-matters",
"version": "0.4.1",
"version": "0.4.2",
"description": "A React-Native utility belt for scaling the size your apps UI across different sized devices",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 68c63b0

Please sign in to comment.