Skip to content

Commit

Permalink
Merge pull request #70 from Trendyol/next
Browse files Browse the repository at this point in the history
feat(box): add forwardRef
  • Loading branch information
gokselpirnal authored Aug 15, 2024
2 parents c3aeed4 + 42a7b2a commit f2883ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/trendyol/baklava-react-native.git"
"url": "https://github.com/Trendyol/baklava-react-native.git"
},
"license": "MIT",
"scripts": {
Expand Down
41 changes: 23 additions & 18 deletions src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,33 @@ const restyleFunctions = composeRestyleFunctions<Theme, RestyleProps>([

export type BoxProps = RNViewProps & RestyleProps;

const Box = ({ testID, accessibilityLabel, accessible, ...rest }: BoxProps) => {
const props = useRestyle(restyleFunctions, rest);
const Box = React.forwardRef(
(
{ testID, accessibilityLabel, accessible, ...rest }: BoxProps,
ref: React.ForwardedRef<RNView>,
) => {
const props = useRestyle(restyleFunctions, rest);

const testProps = React.useMemo(() => {
const result: RNViewProps = {
accessible: false,
accessibilityLabel: undefined,
testID: undefined,
};
const testProps = React.useMemo(() => {
const result: RNViewProps = {
accessible: false,
accessibilityLabel: undefined,
testID: undefined,
};

if (!(testID || accessibilityLabel)) {
return result;
}
if (!(testID || accessibilityLabel)) {
return result;
}

result.accessible = accessible ?? true;
result.accessibilityLabel = accessibilityLabel ?? testID;
result.testID = testID ?? accessibilityLabel;
result.accessible = accessible ?? true;
result.accessibilityLabel = accessibilityLabel ?? testID;
result.testID = testID ?? accessibilityLabel;

return result;
}, [testID, accessibilityLabel, accessible]);
return result;
}, [testID, accessibilityLabel, accessible]);

return <RNView {...props} {...testProps} />;
};
return <RNView {...props} {...testProps} ref={ref} />;
},
);

export default Box;

0 comments on commit f2883ff

Please sign in to comment.