Skip to content
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

Remove defaultProps from MeasureElement component #1818

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions src/components/devsupport/components/measure/measure.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export type MeasuringElement = React.ReactElement;
* but `force` property may be used to measure any time it's needed.
* DON'T USE THIS FLAG IF THE COMPONENT RENDERS FIRST TIME OR YOU KNOW `onLayout` WILL BE CALLED.
*/
export const MeasureElement: React.FC<MeasureElementProps> = (props): MeasuringElement => {
export const MeasureElement: React.FC<MeasureElementProps> = ({
force = false,
shouldUseTopInsets = false,
onMeasure,
children
}): MeasuringElement => {

const ref = React.useRef();

Expand All @@ -67,9 +72,9 @@ export const MeasureElement: React.FC<MeasureElementProps> = (props): MeasuringE
if (!w && !h) {
measureSelf();
} else {
const originY = props.shouldUseTopInsets ? y + StatusBar.currentHeight || 0 : y;
const originY = shouldUseTopInsets ? y + StatusBar.currentHeight || 0 : y;
const frame: Frame = bindToWindow(new Frame(x, originY, w, h), Frame.window());
props.onMeasure(frame);
onMeasure(frame);
}
};

Expand All @@ -78,13 +83,9 @@ export const MeasureElement: React.FC<MeasureElementProps> = (props): MeasuringE
UIManager.measureInWindow(node, onUIManagerMeasure);
};

if (props.force) {
if (force) {
measureSelf();
}

return React.cloneElement(props.children, { ref, onLayout: measureSelf });
};

MeasureElement.defaultProps = {
shouldUseTopInsets: false,
return React.cloneElement(children, { ref, onLayout: measureSelf });
};