Skip to content

Implementation for onContentSizeChange property for TextInput for fabric #14479

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 8 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Implement the onContentSizeChange property for the fabric implementation of TextInput.",
"packageName": "react-native-windows",
"email": "satkh@microsoft.com",
"dependentChangeType": "none"
}
15 changes: 15 additions & 0 deletions packages/playground/Samples/textinput.tsx
Original file line number Diff line number Diff line change
@@ -41,6 +41,10 @@ export default class Bootstrap extends React.Component<{}, any> {
console.log('keyboardDidHide');
};

setHeightAndWidth = (height: number, width: number) => {
console.log(' onContentSizeChange height: ' + height + ' width: ' + width);
};

componentWillUnmount() {
this.didShowEmitterSubscription.remove();
this.didHideEmitterSubscription.remove();
@@ -148,6 +152,17 @@ export default class Bootstrap extends React.Component<{}, any> {
style={[styles.input, {letterSpacing: 5.1}]}
placeholder={'Letter Spacing'}
/>
<TextInput
style={styles.input}
multiline
onContentSizeChange={event =>
this.setHeightAndWidth(
event.nativeEvent.contentSize.height,
event.nativeEvent.contentSize.width,
)
}
placeholder={'content size change'}
/>
<Button
title={
this.state.passwordHidden
Original file line number Diff line number Diff line change
@@ -1132,6 +1132,15 @@ void WindowsTextInputComponentView::updateLayoutMetrics(

if (newWidth != m_imgWidth || newHeight != m_imgHeight) {
m_drawingSurface = nullptr; // Invalidate surface if we get a size change

// call onContentSizeChange event for multiline TextInput
if (m_eventEmitter && !m_comingFromJS && m_multiline) {
auto emitter = std::static_pointer_cast<const facebook::react::WindowsTextInputEventEmitter>(m_eventEmitter);
facebook::react::WindowsTextInputEventEmitter::OnContentSizeChange onContentSizeChangeArgs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is the content size. This is the size of the textinput - But I think onContentSize is supposed to be the size of the text content. So if there is more text that fits within the TextInput bounds, and the TextInput starts scrolling, then onContentSize would report a value larger than the layoutMetrics.frame.size.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, verified in Expo Snack - In 2 line multiline textinput, as I add more and more lines of text the contentSize increases even through the textinput itself does not increase in size.

onContentSizeChangeArgs.contentSize.width = layoutMetrics.frame.size.width * layoutMetrics.pointScaleFactor;
onContentSizeChangeArgs.contentSize.height = layoutMetrics.frame.size.height * layoutMetrics.pointScaleFactor;
emitter->onContentSizeChange(onContentSizeChangeArgs);
}
}

m_imgWidth = newWidth;