mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
97c7c6a4b6
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: https://github.com/facebook/react-native/pull/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
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <react/renderer/attributedstring/AttributedString.h>
|
|
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class TextInputMetrics {
|
|
public:
|
|
std::string text;
|
|
AttributedString::Range selectionRange;
|
|
// ScrollView-like metrics
|
|
Size contentSize;
|
|
Point contentOffset;
|
|
EdgeInsets contentInset;
|
|
Size containerSize;
|
|
int eventCount;
|
|
Size layoutMeasurement;
|
|
float zoomScale;
|
|
};
|
|
|
|
class KeyPressMetrics {
|
|
public:
|
|
std::string text;
|
|
int eventCount;
|
|
};
|
|
|
|
class TextInputEventEmitter : public ViewEventEmitter {
|
|
public:
|
|
using ViewEventEmitter::ViewEventEmitter;
|
|
|
|
void onFocus(TextInputMetrics const &textInputMetrics) const;
|
|
void onBlur(TextInputMetrics const &textInputMetrics) const;
|
|
void onChange(TextInputMetrics const &textInputMetrics) const;
|
|
void onChangeSync(TextInputMetrics const &textInputMetrics) const;
|
|
void onContentSizeChange(TextInputMetrics const &textInputMetrics) const;
|
|
void onSelectionChange(TextInputMetrics const &textInputMetrics) const;
|
|
void onEndEditing(TextInputMetrics const &textInputMetrics) const;
|
|
void onSubmitEditing(TextInputMetrics const &textInputMetrics) const;
|
|
void onKeyPress(KeyPressMetrics const &keyPressMetrics) const;
|
|
void onKeyPressSync(KeyPressMetrics const &keyPressMetrics) const;
|
|
void onScroll(TextInputMetrics const &textInputMetrics) const;
|
|
|
|
private:
|
|
void dispatchTextInputEvent(
|
|
std::string const &name,
|
|
TextInputMetrics const &textInputMetrics,
|
|
EventPriority priority = EventPriority::AsynchronousBatched) const;
|
|
|
|
void dispatchTextInputContentSizeChangeEvent(
|
|
std::string const &name,
|
|
TextInputMetrics const &textInputMetrics,
|
|
EventPriority priority = EventPriority::AsynchronousBatched) const;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|