Skip to content

Commit

Permalink
translate regex to support %
Browse files Browse the repository at this point in the history
  • Loading branch information
intergalacticspacehighway committed Feb 25, 2024
1 parent 6829aa2 commit 8879930
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const _getKeyAndValueFromCSSTransform: (
| $TEMPORARY$string<'translateY'>,
args: string,
) => {key: string, value?: number[] | number | string} = (key, args) => {
const argsWithUnitsRegex = new RegExp(/([+-]?\d+(\.\d+)?)([a-zA-Z]+)?/g);
const argsWithUnitsRegex = new RegExp(/([+-]?\d+(\.\d+)?)([a-zA-Z%]+)?/g);

switch (key) {
case 'matrix':
Expand All @@ -88,7 +88,11 @@ const _getKeyAndValueFromCSSTransform: (
missingUnitOfMeasurement = true;
}

parsedArgs.push(value);
if (unitOfMeasurement === '%') {
parsedArgs.push(`${value}%`);
} else {
parsedArgs.push(value);
}
}

if (__DEV__) {
Expand Down
17 changes: 17 additions & 0 deletions packages/rn-tester/js/examples/Transform/TransformExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ function Flip() {
);
}

function TranslatePercentage() {
return <View style={styles.translatePercentageView} />;
}

const styles = StyleSheet.create({
container: {
height: 500,
Expand Down Expand Up @@ -277,6 +281,12 @@ const styles = StyleSheet.create({
height: 100,
transformOrigin: 'top left',
},
translatePercentageView: {
transform: 'translate(50%)',
padding: 50,
alignSelf: 'flex-start',
backgroundColor: 'lightblue',
},
});

exports.title = 'Transforms';
Expand Down Expand Up @@ -396,4 +406,11 @@ exports.examples = [
return <TransformOriginExample />;
},
},
{
title: 'Translate Percentage',
description: "transform: 'translate(50%)'",
render(): Node {
return <TranslatePercentage />;
},
},
];

0 comments on commit 8879930

Please sign in to comment.