Skip to content

Commit

Permalink
feat(box): add forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
gokselpirnal committed Aug 15, 2024
1 parent c3aeed4 commit 2272fad
Showing 1 changed file with 23 additions and 18 deletions.
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 2272fad

Please sign in to comment.