Skip to content

Feat/ support negative margin modifiers #2562

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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f9af399
add negative modifiers support
lidord-wix Apr 17, 2023
abcbeb1
FlashList optional dependency (#2559)
adids1221 Apr 17, 2023
52628e4
support labelStyle in ActionSheet options (#2564)
lidord-wix Apr 18, 2023
513671f
Calendar - fix week number line break
Inbal-Tish Apr 19, 2023
b8509b5
SortableList - add driver and test (#2568)
M-i-k-e-l Apr 19, 2023
e5d5bfd
Add segmentStyle prop to SegmentedControl (#2563)
lidord-wix Apr 19, 2023
d64a02c
Changed the FlashList using syntax according to the WebEditor errors …
adids1221 Apr 19, 2023
11eb584
Feat/calendar (#2503)
Inbal-Tish Apr 19, 2023
2d5a063
SortableList - newHeight in tests (#2571)
M-i-k-e-l Apr 20, 2023
188f886
Picker - remove commented out code related to 'renderNativePicker' de…
Inbal-Tish Apr 23, 2023
65e7279
Incubator.Dialog - fix RN Modal native calls on RN71 (#2573)
M-i-k-e-l Apr 23, 2023
a257263
CharCounter now working with emojis (16-bit code) (#2570)
adids1221 Apr 27, 2023
81932b1
SortableList - adding important note
Inbal-Tish Apr 27, 2023
52a2cb6
fix wheelpicker in android (#2558)
adids1221 May 1, 2023
dc7a7be
Align LogService with console (#2577)
M-i-k-e-l May 2, 2023
29dd169
Incubator.Dialog - fix test after RN71 bug fix (#2575)
M-i-k-e-l May 3, 2023
b82be40
Replacing 'react-native-text-size' with wix fork (#2542)
Inbal-Tish May 8, 2023
66789d6
Enable TS check on demo files and fix all errors (#2585)
ethanshar May 9, 2023
a4e8098
Revert changes in margin modifiers typings
ethanshar May 10, 2023
6059943
SortableGridList tests (#2586)
lidord-wix May 11, 2023
f9fe920
Upgrade reanimated to 2.17 (#2587)
M-i-k-e-l May 11, 2023
a477fd6
HintsScreen - allow configuration (#2590)
M-i-k-e-l May 15, 2023
a6bb5ab
Move to reanimated 3 (#2593)
M-i-k-e-l May 15, 2023
d17fda5
Merge branch 'master' into feat/support_negative_margins_modifiers
lidord-wix May 15, 2023
f212860
support number values for margin and padding
lidord-wix May 15, 2023
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
2 changes: 1 addition & 1 deletion demo/src/screens/PlaygroundScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class PlaygroundScreen extends Component {
render() {
return (
<View bg-grey80 flex padding-20>
<View marginT-20>
<View marginT={20}>
<TextField migrate placeholder="Placeholder"/>
</View>
<Card height={100} center padding-20>
Expand Down
45 changes: 36 additions & 9 deletions src/commons/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {SpacingLiterals} from '../style/spacings';
import {colorsPalette} from '../style/colorsPalette';
export const FLEX_KEY_PATTERN = /^flex(G|S)?(-\d*)?$/;
export const PADDING_KEY_PATTERN = new RegExp(`padding[LTRBHV]?-([0-9]*|${Spacings.getKeysPattern()})`);
export const MARGIN_KEY_PATTERN = new RegExp(`margin[LTRBHV]?-([0-9]*|${Spacings.getKeysPattern()})`);
export const MARGIN_KEY_PATTERN = new RegExp(`margin[LTRBHV]*-([0-9]*|${Spacings.getKeysPattern()})`);
export const ALIGNMENT_KEY_PATTERN = /(left|top|right|bottom|center|centerV|centerH|spread)/;
export const POSITION_KEY_PATTERN = /^abs([F|L|R|T|B|V|H])?$/;
const BACKGROUND_COLOR_KEYS_PATTERN = Colors.getBackgroundKeysPattern();
Expand Down Expand Up @@ -93,6 +93,7 @@ export type AlignmentLiterals =
export type PositionLiterals = 'absF' | 'absL' | 'absR' | 'absT' | 'absB' | 'absV' | 'absH';

export type Modifier<T extends string> = Partial<Record<T, boolean>>;
export type NumberModifier<T extends string> = Partial<Record<T, number>>;
export type CustomModifier = {[key: string]: boolean};

// TODO: migrate other modifiers to the same new structure as Margin modifier, using template literals
Expand All @@ -101,8 +102,8 @@ export type ColorsModifiers = Modifier<ColorLiterals> | CustomModifier;
export type BackgroundColorModifier = Modifier<'bg'>;
export type AlignmentModifiers = Modifier<AlignmentLiterals>;
export type PositionModifiers = Modifier<PositionLiterals>;
export type PaddingModifiers = Modifier<PaddingLiterals>;
export type MarginModifiers = Modifier<MarginLiterals>;
export type PaddingModifiers = NumberModifier<PaddingLiterals>;
export type MarginModifiers = NumberModifier<MarginLiterals>;
// TODO: This caused issue with with some typings that inherit this type
// export type MarginModifiers = Partial<{[key: `${MarginLiterals}-${number}`]: boolean}>;
export type FlexModifiers = Modifier<FlexLiterals>;
Expand Down Expand Up @@ -151,6 +152,8 @@ export function extractTypographyValue(props: Dictionary<any>): object | undefin
export function extractPaddingValues(props: Dictionary<any>) {
const paddings: Partial<Record<NativePaddingKeyType, number>> = {};
const paddingPropsKeys = Object.keys(props).filter(key => PADDING_KEY_PATTERN.test(key));
const numberPaddingPropsKeys = Object.keys(props).filter(key => Object.keys(PADDING_VARIATIONS).includes(key));

_.forEach(paddingPropsKeys, key => {
if (props[key] === true) {
const [paddingKey, paddingValue] = key.split('-') as [keyof typeof PADDING_VARIATIONS, string];
Expand All @@ -163,25 +166,49 @@ export function extractPaddingValues(props: Dictionary<any>) {
}
});

_.forEach(numberPaddingPropsKeys, key => {
const paddingVariation = PADDING_VARIATIONS[key as keyof typeof PADDING_VARIATIONS];

if (!isNaN(Number(props[key]))) {
paddings[paddingVariation] = Number(props[key]);
} else if (Spacings.getKeysPattern().test(props[key])) {
paddings[paddingVariation] = Spacings[props[key] as keyof typeof SpacingLiterals];
}
});

return paddings;
}

export function extractMarginValues(props: Dictionary<any>) {
const margins: Partial<Record<NativeMarginModifierKeyType, number>> = {};
const marginPropsKeys = Object.keys(props).filter(key => MARGIN_KEY_PATTERN.test(key));
const numberMarginPropsKeys = Object.keys(props).filter(key => Object.keys(MARGIN_VARIATIONS).includes(key));

_.forEach(marginPropsKeys, key => {
if (props[key] === true) {
const [marginKey, marginValue] = key.split('-') as [keyof typeof MARGIN_VARIATIONS, string];
const paddingVariation = MARGIN_VARIATIONS[marginKey];
if (!isNaN(Number(marginValue))) {
margins[paddingVariation] = Number(marginValue);
} else if (Spacings.getKeysPattern().test(marginValue)) {
margins[paddingVariation] = Spacings[marginValue as keyof typeof SpacingLiterals];
const [marginKey, marginValue, negativeMarginValue] = key.split('-') as [keyof typeof MARGIN_VARIATIONS, string, string | undefined];
const marginVariation = MARGIN_VARIATIONS[marginKey];
const value = negativeMarginValue ?? marginValue;
const sign = negativeMarginValue ? -1 : 1;

if (!isNaN(Number(value))) {
margins[marginVariation] = sign * Number(value);
} else if (Spacings.getKeysPattern().test(value)) {
margins[marginVariation] = sign * Spacings[value as keyof typeof SpacingLiterals];
}
}
});

_.forEach(numberMarginPropsKeys, key => {
const marginVariation = MARGIN_VARIATIONS[key as keyof typeof MARGIN_VARIATIONS];

if (!isNaN(Number(props[key]))) {
margins[marginVariation] = Number(props[key]);
} else if (Spacings.getKeysPattern().test(props[key])) {
margins[marginVariation] = Spacings[props[key] as keyof typeof SpacingLiterals];
}
});

return margins;
}

Expand Down