Skip to content

Commit 719d61e

Browse files
authored
Support combining multiple abs modifiers (#1509)
1 parent c6f7e22 commit 719d61e

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

generatedTypes/src/commons/modifiers.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ export declare function extractTypographyValue(props: Dictionary<any>): object |
8080
export declare function extractPaddingValues(props: Dictionary<any>): Partial<Record<NativePaddingKeyType, number>>;
8181
export declare function extractMarginValues(props: Dictionary<any>): Partial<Record<NativeMarginModifierKeyType, number>>;
8282
export declare function extractAlignmentsValues(props: Dictionary<any>): any;
83-
export declare function extractPositionStyle(props: Dictionary<any>): {
84-
position: "absolute";
85-
} | undefined;
83+
export declare function extractPositionStyle(props: Dictionary<any>): {} | undefined;
8684
export declare function extractFlexStyle(props: Dictionary<any>): Partial<Record<NativeFlexModifierKeyType, number>> | undefined;
8785
export declare function extractAccessibilityProps(props?: any): Partial<any>;
8886
export declare function extractAnimationProps(props?: any): Pick<any, "onAnimationEnd" | "animation" | "duration" | "delay" | "direction" | "easing" | "iterationCount" | "transition" | "onAnimationBegin" | "useNativeDriver">;

src/commons/__tests__/modifiers.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ describe('Modifiers', () => {
249249
it('should return absolute with horizontal values', () => {
250250
expect(uut.extractPositionStyle({absH: true})).toEqual({position: 'absolute', left: 0, right: 0});
251251
});
252+
253+
it('should combine multiple abs modifiers', () => {
254+
expect(uut.extractPositionStyle({absB: true, absR: true})).toEqual({position: 'absolute', bottom: 0, right: 0});
255+
expect(uut.extractPositionStyle({absH: true, absV: true})).toEqual({position: 'absolute', top: 0, left: 0, bottom: 0, right: 0});
256+
});
252257
});
253258

254259
describe('extractFlexStyle - flex modifier', () => {

src/commons/modifiers.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,20 @@ export function extractPositionStyle(props: Dictionary<any>) {
231231
} as const;
232232

233233
const keys = Object.keys(props);
234-
const positionProp = _.findLast(keys, prop => POSITION_KEY_PATTERN.test(prop) && !!props[prop]);
235-
if (positionProp) {
234+
const positionProps = _.filter(keys, prop => POSITION_KEY_PATTERN.test(prop) && !!props[prop]);
235+
let style = {};
236+
237+
_.forEach(positionProps, positionProp => {
236238
const positionVariationKey = _.split(positionProp, 'abs')[1] as keyof typeof POSITION_CONVERSIONS;
237239
if (positionVariationKey) {
238240
const positionVariation = POSITION_CONVERSIONS[positionVariationKey];
239241
const styleKey = `absolute${positionVariation}` as keyof typeof styles;
240-
return styles[styleKey];
242+
style = {...style, ...styles[styleKey]};
241243
}
242-
return styles.absolute;
243-
}
244+
style = {...style, ...styles.absolute};
245+
});
246+
247+
return _.isEmpty(style) ? undefined : style;
244248
}
245249

246250
export function extractFlexStyle(props: Dictionary<any>): Partial<Record<NativeFlexModifierKeyType, number>> | undefined {

0 commit comments

Comments
 (0)