forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out common parts of TextInputProps between Android/iOS (facebo…
…ok#43431) Summary: ## Changelog: [Internal] - This takes all the common props for TextInput between Android and iOS and factors them out into a single, platform independent props data structure, `BaseTextInputProps`. This way it's both easier to manage the corresponding props, but also making this easier to be used on other platforms. Reviewed By: sammy-SC Differential Revision: D54764898
- Loading branch information
1 parent
81d39d9
commit 3901263
Showing
7 changed files
with
253 additions
and
238 deletions.
There are no files selected for viewing
179 changes: 179 additions & 0 deletions
179
packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "BaseTextInputProps.h" | ||
|
||
#include <react/renderer/core/propsConversions.h> | ||
|
||
#include <react/renderer/core/Props.h> | ||
#include <react/renderer/core/PropsMacros.h> | ||
|
||
#include <react/renderer/graphics/Color.h> | ||
|
||
#include <react/renderer/attributedstring/TextAttributes.h> | ||
#include <react/renderer/attributedstring/conversions.h> | ||
#include <react/renderer/components/image/conversions.h> | ||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/core/graphicsConversions.h> | ||
#include <react/renderer/graphics/Color.h> | ||
#include <react/renderer/imagemanager/primitives.h> | ||
#include <react/utils/CoreFeatures.h> | ||
|
||
namespace facebook::react { | ||
|
||
BaseTextInputProps::BaseTextInputProps( | ||
const PropsParserContext& context, | ||
const BaseTextInputProps& sourceProps, | ||
const RawProps& rawProps) | ||
: ViewProps(context, sourceProps, rawProps), | ||
BaseTextProps(context, sourceProps, rawProps), | ||
paragraphAttributes(convertRawProp( | ||
context, | ||
rawProps, | ||
sourceProps.paragraphAttributes, | ||
{})), | ||
defaultValue(convertRawProp( | ||
context, | ||
rawProps, | ||
"defaultValue", | ||
sourceProps.defaultValue, | ||
{})), | ||
placeholder(convertRawProp( | ||
context, | ||
rawProps, | ||
"placeholder", | ||
sourceProps.placeholder, | ||
{})), | ||
placeholderTextColor(convertRawProp( | ||
context, | ||
rawProps, | ||
"placeholderTextColor", | ||
sourceProps.placeholderTextColor, | ||
{})), | ||
cursorColor(convertRawProp( | ||
context, | ||
rawProps, | ||
"cursorColor", | ||
sourceProps.cursorColor, | ||
{})), | ||
selectionColor(convertRawProp( | ||
context, | ||
rawProps, | ||
"selectionColor", | ||
sourceProps.selectionColor, | ||
{})), | ||
selectionHandleColor(convertRawProp( | ||
context, | ||
rawProps, | ||
"selectionHandleColor", | ||
sourceProps.selectionHandleColor, | ||
{})), | ||
underlineColorAndroid(convertRawProp( | ||
context, | ||
rawProps, | ||
"underlineColorAndroid", | ||
sourceProps.underlineColorAndroid, | ||
{})), | ||
maxLength(convertRawProp( | ||
context, | ||
rawProps, | ||
"maxLength", | ||
sourceProps.maxLength, | ||
{})), | ||
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})), | ||
mostRecentEventCount(convertRawProp( | ||
context, | ||
rawProps, | ||
"mostRecentEventCount", | ||
sourceProps.mostRecentEventCount, | ||
{})), | ||
autoFocus(convertRawProp( | ||
context, | ||
rawProps, | ||
"autoFocus", | ||
sourceProps.autoFocus, | ||
{})){}; | ||
|
||
void BaseTextInputProps::setProp( | ||
const PropsParserContext& context, | ||
RawPropsPropNameHash hash, | ||
const char* propName, | ||
const RawValue& value) { | ||
ViewProps::setProp(context, hash, propName, value); | ||
BaseTextProps::setProp(context, hash, propName, value); | ||
|
||
static auto defaults = BaseTextInputProps{}; | ||
|
||
// ParagraphAttributes has its own switch statement - to keep all | ||
// of these fields together, and because there are some collisions between | ||
// propnames parsed here and outside of ParagraphAttributes. For example, | ||
// textBreakStrategy is duplicated. | ||
// This code is also duplicated in ParagraphProps. | ||
static auto paDefaults = ParagraphAttributes{}; | ||
switch (hash) { | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
maximumNumberOfLines, | ||
"numberOfLines"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, value, paragraphAttributes, ellipsizeMode, "ellipsizeMode"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
textBreakStrategy, | ||
"textBreakStrategy"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
adjustsFontSizeToFit, | ||
"adjustsFontSizeToFit"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
minimumFontSize, | ||
"minimumFontSize"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
maximumFontSize, | ||
"maximumFontSize"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
includeFontPadding, | ||
"includeFontPadding"); | ||
REBUILD_FIELD_SWITCH_CASE( | ||
paDefaults, | ||
value, | ||
paragraphAttributes, | ||
android_hyphenationFrequency, | ||
"android_hyphenationFrequency"); | ||
} | ||
|
||
switch (hash) { | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(underlineColorAndroid); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(autoFocus); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(maxLength); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(placeholder); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(placeholderTextColor); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(selectionColor); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(selectionHandleColor); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(defaultValue); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(cursorColor); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(text); | ||
RAW_SET_PROP_SWITCH_CASE_BASIC(mostRecentEventCount); | ||
} | ||
} | ||
|
||
} // namespace facebook::react |
66 changes: 66 additions & 0 deletions
66
packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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/ParagraphAttributes.h> | ||
#include <react/renderer/components/text/BaseTextProps.h> | ||
#include <react/renderer/components/view/ViewProps.h> | ||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/graphics/Color.h> | ||
#include <string> | ||
|
||
namespace facebook::react { | ||
|
||
class BaseTextInputProps : public ViewProps, public BaseTextProps { | ||
public: | ||
BaseTextInputProps() = default; | ||
BaseTextInputProps( | ||
const PropsParserContext& context, | ||
const BaseTextInputProps& sourceProps, | ||
const RawProps& rawProps); | ||
|
||
void setProp( | ||
const PropsParserContext& context, | ||
RawPropsPropNameHash hash, | ||
const char* propName, | ||
const RawValue& value); | ||
|
||
#pragma mark - Props | ||
|
||
/* | ||
* Contains all prop values that affect visual representation of the | ||
* paragraph. | ||
*/ | ||
ParagraphAttributes paragraphAttributes{}; | ||
|
||
std::string defaultValue{}; | ||
|
||
std::string placeholder{}; | ||
SharedColor placeholderTextColor{}; | ||
|
||
/* | ||
* Tint colors | ||
*/ | ||
SharedColor cursorColor{}; | ||
SharedColor selectionColor{}; | ||
SharedColor selectionHandleColor{}; | ||
// TODO: Rename to `tintColor` and make universal. | ||
SharedColor underlineColorAndroid{}; | ||
|
||
int maxLength{}; | ||
|
||
/* | ||
* "Private" (only used by TextInput.js) props | ||
*/ | ||
std::string text{}; | ||
int mostRecentEventCount{0}; | ||
|
||
bool autoFocus{false}; | ||
}; | ||
|
||
} // namespace facebook::react |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.