-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
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 having this used on other platforms. Differential Revision: D54764898
- Loading branch information
1 parent
bdca260
commit 5e644b4
Showing
6 changed files
with
240 additions
and
214 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
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,164 @@ | ||
/* | ||
* 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/attributedstring/conversions.h> | ||
#include <react/renderer/core/graphicsConversions.h> | ||
#include <react/renderer/core/propsConversions.h> | ||
|
||
namespace facebook::react { | ||
|
||
BaseTextInputProps::BaseTextInputProps( | ||
const PropsParserContext& context, | ||
const BaseTextInputProps& sourceProps, | ||
const RawProps& 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) { | ||
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 |
67 changes: 67 additions & 0 deletions
67
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,67 @@ | ||
/* | ||
* 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/core/Props.h> | ||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/core/propsConversions.h> | ||
#include <react/renderer/graphics/Color.h> | ||
#include <string> | ||
|
||
namespace facebook::react { | ||
|
||
class BaseTextInputProps : 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 const defaultValue{}; | ||
|
||
std::string const placeholder{}; | ||
const SharedColor placeholderTextColor{}; | ||
|
||
/* | ||
* Tint colors | ||
*/ | ||
const SharedColor cursorColor{}; | ||
const SharedColor selectionColor{}; | ||
const SharedColor selectionHandleColor{}; | ||
// TODO: Rename to `tintColor` and make universal. | ||
const SharedColor underlineColorAndroid{}; | ||
|
||
int maxLength{}; | ||
|
||
/* | ||
* "Private" (only used by TextInput.js) props | ||
*/ | ||
std::string const text{}; | ||
const int mostRecentEventCount{0}; | ||
|
||
bool autoFocus{false}; | ||
}; | ||
|
||
} // namespace facebook::react |
Oops, something went wrong.