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

fix: dispatch ContentSizeChange event on Fabric on iOS #35816

Conversation

WoLewicki
Copy link
Contributor

Summary

On Fabric, onContentSizeChange of TextInput component was never fired on iOS, since the logic dispatching it was implemented in RCTBaseTextInputShadowView on Paper:

. This class is not used on Fabric, therefore the event was never dispatched. On Paper, it was dispatched in dirtyLayout method, so I added dispatching of this event based on the change of content size in layoutSubviews method, since this method seems the closest one on Fabric. I am not sure if it is the best place for it though.

Changelog

[IOS] [ADDED] - dispatch onContentSizeChange event on Fabric.

Test Plan

Try to use onContentSizeChange callback in TextInput component:

import React from 'react';
import {TextInput, SafeAreaView} from 'react-native';

const App = () => {
  return (
    <SafeAreaView style={{flex: 1, backgroundColor: 'red'}}>
      <TextInput
        multiline={true}
        placeholder="type here"
        onContentSizeChange={e => console.log(e)}
      />
    </SafeAreaView>
  );
};

export default App;

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 12, 2023
@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,493,485 +0
android hermes armeabi-v7a 7,813,452 +0
android hermes x86 8,967,867 +0
android hermes x86_64 8,827,371 +0
android jsc arm64-v8a 9,679,111 +0
android jsc armeabi-v7a 8,412,818 +0
android jsc x86 9,742,216 +0
android jsc x86_64 10,220,841 +0

Base commit: 8befb74
Branch: main

@sammy-SC
Copy link
Contributor

Hey @WoLewicki,

thank you for the PR!

TextInput can listen to size changes inside updateLayoutMetrics, I think that is better place for it.

@sammy-SC sammy-SC requested review from sammy-SC and philIip January 12, 2023 19:22
@facebook-github-bot
Copy link
Contributor

@sammy-SC has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 13, 2023
@facebook-github-bot
Copy link
Contributor

@sammy-SC merged this pull request in 97c7c6a.

@sammy-SC
Copy link
Contributor

Thanks @WoLewicki, this has been merged.

OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
On Fabric, `onContentSizeChange` of `TextInput` component was never fired on `iOS`, since the logic dispatching it was implemented in `RCTBaseTextInputShadowView` on Paper: https://github.com/facebook/react-native/blob/0f8dc067ac079f7b14696cfcafa37e3ec19a0409/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m#L105. This class is not used on Fabric, therefore the event was never dispatched. On Paper, it was dispatched in `dirtyLayout` method,  so I added dispatching of this event based on the change of content size in `layoutSubviews` method, since this method seems the closest one on Fabric. I am not sure if it is the best place for it though.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [ADDED] - dispatch `onContentSizeChange` event on Fabric.

Pull Request resolved: facebook#35816

Test Plan:
Try to use `onContentSizeChange` callback in `TextInput` component:
```tsx
import React from 'react';
import {TextInput, SafeAreaView} from 'react-native';

const App = () => {
  return (
    <SafeAreaView style={{flex: 1, backgroundColor: 'red'}}>
      <TextInput
        multiline={true}
        placeholder="type here"
        onContentSizeChange={e => console.log(e)}
      />
    </SafeAreaView>
  );
};

export default App;

```

Reviewed By: christophpurrer

Differential Revision: D42499974

Pulled By: sammy-SC

fbshipit-source-id: 3e010ff096cf91cb3e7b87ed2753e9d0e7be9650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants