mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix TextInput left/right padding
Summary: This fixes two things: 1) Currently it only respects Start and End padding, and if there's a Theme default, it will override Left/Right padding. Whoops. 2) Currently it doesn't respect when a TextInput starts with padding, but then is removed. This resolves both. It still does not account for RTL support. Changelog: [Internal] Fix AndroidTextInput padding Reviewed By: mdvacca Differential Revision: D20573151 fbshipit-source-id: e89791641b6699e728cde9dbd661a8c21485fbc8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
987b902dc0
commit
fb9a7be2bd
+66
-28
@@ -13,6 +13,29 @@
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static bool hasValue(
|
||||
const RawProps &rawProps,
|
||||
bool defaultValue,
|
||||
const char *name,
|
||||
const char *prefix,
|
||||
const char *suffix) {
|
||||
auto rawValue = rawProps.at(name, prefix, suffix);
|
||||
|
||||
// No change to prop - use default
|
||||
if (rawValue == nullptr) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
// Value passed from JS
|
||||
if (rawValue->hasValue()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Null/undefined passed in, indicating that we should use the default
|
||||
// platform value - thereby resetting this
|
||||
return false;
|
||||
}
|
||||
|
||||
AndroidTextInputProps::AndroidTextInputProps(
|
||||
const AndroidTextInputProps &sourceProps,
|
||||
const RawProps &rawProps)
|
||||
@@ -225,36 +248,48 @@ AndroidTextInputProps::AndroidTextInputProps(
|
||||
convertRawProp(rawProps, sourceProps.paragraphAttributes, {})),
|
||||
// See AndroidTextInputComponentDescriptor for usage
|
||||
// TODO T63008435: can these, and this feature, be removed entirely?
|
||||
hasPaddingLeft(
|
||||
sourceProps.hasPaddingLeft ||
|
||||
rawProps.at("", "padding", "") != nullptr ||
|
||||
rawProps.at("Left", "padding", "") != nullptr ||
|
||||
rawProps.at("Horizontal", "padding", "") != nullptr),
|
||||
hasPadding(hasValue(rawProps, sourceProps.hasPadding, "", "padding", "")),
|
||||
hasPaddingHorizontal(hasValue(
|
||||
rawProps,
|
||||
sourceProps.hasPaddingHorizontal,
|
||||
"Horizontal",
|
||||
"padding",
|
||||
"")),
|
||||
hasPaddingVertical(hasValue(
|
||||
rawProps,
|
||||
sourceProps.hasPaddingVertical,
|
||||
"Vertical",
|
||||
"padding",
|
||||
"")),
|
||||
hasPaddingLeft(hasValue(
|
||||
rawProps,
|
||||
sourceProps.hasPaddingLeft,
|
||||
"Left",
|
||||
"padding",
|
||||
"")),
|
||||
hasPaddingTop(
|
||||
sourceProps.hasPaddingTop ||
|
||||
rawProps.at("", "padding", "") != nullptr ||
|
||||
rawProps.at("Top", "padding", "") != nullptr ||
|
||||
rawProps.at("Vertical", "padding", "") != nullptr),
|
||||
hasPaddingRight(
|
||||
sourceProps.hasPaddingRight ||
|
||||
rawProps.at("", "padding", "") != nullptr ||
|
||||
rawProps.at("Right", "padding", "") != nullptr ||
|
||||
rawProps.at("Horizontal", "padding", "") != nullptr),
|
||||
hasPaddingBottom(
|
||||
sourceProps.hasPaddingBottom ||
|
||||
rawProps.at("", "padding", "") != nullptr ||
|
||||
rawProps.at("Bottom", "padding", "") != nullptr ||
|
||||
rawProps.at("Vertical", "padding", "") != nullptr),
|
||||
hasPaddingStart(
|
||||
sourceProps.hasPaddingStart ||
|
||||
rawProps.at("", "padding", "") != nullptr ||
|
||||
rawProps.at("Start", "padding", "") != nullptr ||
|
||||
rawProps.at("Horizontal", "padding", "") != nullptr),
|
||||
hasValue(rawProps, sourceProps.hasPaddingTop, "Top", "padding", "")),
|
||||
hasPaddingRight(hasValue(
|
||||
rawProps,
|
||||
sourceProps.hasPaddingRight,
|
||||
"Right",
|
||||
"padding",
|
||||
"")),
|
||||
hasPaddingBottom(hasValue(
|
||||
rawProps,
|
||||
sourceProps.hasPaddingBottom,
|
||||
"Bottom",
|
||||
"padding",
|
||||
"")),
|
||||
hasPaddingStart(hasValue(
|
||||
rawProps,
|
||||
sourceProps.hasPaddingStart,
|
||||
"Start",
|
||||
"padding",
|
||||
"")),
|
||||
hasPaddingEnd(
|
||||
sourceProps.hasPaddingEnd ||
|
||||
rawProps.at("", "padding", "") != nullptr ||
|
||||
rawProps.at("End", "padding", "") != nullptr ||
|
||||
rawProps.at("Horizontal", "padding", "") != nullptr) {}
|
||||
hasValue(rawProps, sourceProps.hasPaddingEnd, "End", "padding", "")) {
|
||||
}
|
||||
|
||||
// TODO T53300085: support this in codegen; this was hand-written
|
||||
folly::dynamic AndroidTextInputProps::getDynamic() const {
|
||||
@@ -309,6 +344,9 @@ folly::dynamic AndroidTextInputProps::getDynamic() const {
|
||||
props["mostRecentEventCount"] = mostRecentEventCount;
|
||||
props["text"] = text;
|
||||
|
||||
props["hasPadding"] = hasPadding;
|
||||
props["hasPaddingHorizontal"] = hasPaddingHorizontal;
|
||||
props["hasPaddingVertical"] = hasPaddingVertical;
|
||||
props["hasPaddingStart"] = hasPaddingStart;
|
||||
props["hasPaddingEnd"] = hasPaddingEnd;
|
||||
props["hasPaddingLeft"] = hasPaddingLeft;
|
||||
|
||||
Reference in New Issue
Block a user