Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support round in TS types #84

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading