|
1 | | -import { StyleSheet } from 'react-native'; |
2 | 1 | import type { ConstantsType, Fn, NamedStyles, StyleSheetType } from './type'; |
3 | 2 |
|
4 | 3 | export default class Sheet< |
5 | 4 | T, |
6 | | - S extends NamedStyles<S> | NamedStyles<any>, |
7 | | - O = S |
8 | | - > { |
9 | | - public result: O; |
10 | | - public source: Fn<T, S>; |
11 | | - public nativeSheet: O = {} as O; |
| 5 | + P extends NamedStyles<P> | NamedStyles<any>> { |
| 6 | + public result: StyleSheetType<P>; |
| 7 | + public source: Fn<T, P>; |
12 | 8 |
|
13 | | - constructor(sourceFn: Fn<T, S>) { |
| 9 | + constructor(sourceFn: Fn<T, P>) { |
14 | 10 | this.source = sourceFn; |
15 | | - this.result = {} as O; |
| 11 | + this.result = {} as StyleSheetType<P>; |
16 | 12 | } |
17 | 13 |
|
18 | | - calc(globalVars: T, constants: ConstantsType, activeIndex: number): O { |
| 14 | + calc(globalVars: T, constants: ConstantsType, activeIndex: number): StyleSheetType<P> { |
19 | 15 | this.clearResult(); |
20 | 16 | this.calcStyles(globalVars, constants, activeIndex); |
21 | | - this.calcNative(); |
22 | 17 | return this.getResult(); |
23 | 18 | } |
24 | 19 |
|
25 | | - getResult(): O { |
| 20 | + getResult(): StyleSheetType<P> { |
26 | 21 | return this.result; |
27 | 22 | } |
28 | 23 |
|
@@ -59,16 +54,4 @@ export default class Sheet< |
59 | 54 | }); |
60 | 55 | } |
61 | 56 | } |
62 | | - |
63 | | - calcStyle(key: string, styleProps: any): void { |
64 | | - // @ts-ignore |
65 | | - this.nativeSheet[key] = styleProps; |
66 | | - } |
67 | | - |
68 | | - calcNative(): void { |
69 | | - if (Object.keys(this.result).length) { |
70 | | - const rnStyleSheet = StyleSheet.create(this.nativeSheet); |
71 | | - Object.assign(this.result, rnStyleSheet); |
72 | | - } |
73 | | - } |
74 | 57 | } |
0 commit comments