Skip to content

Commit 8434177

Browse files
Dmitry Rykunfacebook-github-bot
Dmitry Rykun
authored andcommitted
Added Selection prop to TextInputProps
Summary: Changelog: [iOS][Added] 1. Added new primitive type "Selection" to C++ 2. Added property "selection" to TextInputProps 3. Added parser for that Reviewed By: sammy-SC Differential Revision: D30043256 fbshipit-source-id: eefa67ca23759761901cba1d2ab3052877a153a7
1 parent 1d0fb08 commit 8434177

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
208208
if (newTextInputProps.inputAccessoryViewID != oldTextInputProps.inputAccessoryViewID) {
209209
_backedTextInputView.inputAccessoryViewID = RCTNSStringFromString(newTextInputProps.inputAccessoryViewID);
210210
}
211-
212211
[super updateProps:props oldProps:oldProps];
213212

214213
[self setDefaultInputAccessoryView];

ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ TextInputProps::TextInputProps(
8282
"autoFocus",
8383
sourceProps.autoFocus,
8484
{})),
85+
selection(convertRawProp(
86+
context,
87+
rawProps,
88+
"selection",
89+
sourceProps.selection,
90+
better::optional<Selection>())),
8591
inputAccessoryViewID(convertRawProp(
8692
context,
8793
rawProps,
@@ -115,13 +121,5 @@ ParagraphAttributes TextInputProps::getEffectiveParagraphAttributes() const {
115121
return result;
116122
}
117123

118-
#ifdef ANDROID
119-
folly::dynamic TextInputProps::getDynamic() const {
120-
folly::dynamic props = folly::dynamic::object();
121-
props["value"] = value;
122-
return props;
123-
}
124-
#endif
125-
126124
} // namespace react
127125
} // namespace facebook

ReactCommon/react/renderer/components/textinput/iostextinput/TextInputProps.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class TextInputProps final : public ViewProps, public BaseTextProps {
5858
int const mostRecentEventCount{0};
5959

6060
bool autoFocus{false};
61+
better::optional<Selection> selection{};
6162

6263
std::string const inputAccessoryViewID{};
6364

@@ -66,10 +67,6 @@ class TextInputProps final : public ViewProps, public BaseTextProps {
6667
*/
6768
TextAttributes getEffectiveTextAttributes(Float fontSizeMultiplier) const;
6869
ParagraphAttributes getEffectiveParagraphAttributes() const;
69-
70-
#ifdef ANDROID
71-
folly::dynamic getDynamic() const;
72-
#endif
7370
};
7471

7572
} // namespace react

ReactCommon/react/renderer/components/textinput/iostextinput/primitives.h

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ enum class KeyboardType {
7777
VisiblePassword,
7878
};
7979

80+
class Selection final {
81+
public:
82+
int start{0};
83+
int end{0};
84+
};
85+
8086
/*
8187
* Controls features of text inputs.
8288
*/

ReactCommon/react/renderer/components/textinput/iostextinput/propsConversions.h

+33
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,38 @@ static TextInputTraits convertRawProp(
145145
return traits;
146146
}
147147

148+
inline void fromRawValue(
149+
const PropsParserContext &context,
150+
const RawValue &value,
151+
Selection &result) {
152+
if (value.hasType<better::map<std::string, int>>()) {
153+
auto map = (better::map<std::string, int>)value;
154+
for (const auto &pair : map) {
155+
if (pair.first == "start") {
156+
result.start = pair.second;
157+
} else if (pair.first == "end") {
158+
result.end = pair.second;
159+
} else {
160+
LOG(ERROR) << "Unsupported Selection map key: " << pair.first;
161+
react_native_assert(false);
162+
}
163+
}
164+
return;
165+
}
166+
167+
react_native_assert(value.hasType<std::vector<int>>());
168+
if (value.hasType<std::vector<int>>()) {
169+
auto array = (std::vector<int>)value;
170+
react_native_assert(array.size() == 2);
171+
if (array.size() >= 2) {
172+
result = {array.at(0), array.at(1)};
173+
} else {
174+
result = {0, 0};
175+
LOG(ERROR) << "Unsupported Selection vector size: " << array.size();
176+
}
177+
} else {
178+
LOG(ERROR) << "Unsupported Selection type";
179+
}
180+
}
148181
} // namespace react
149182
} // namespace facebook

0 commit comments

Comments
 (0)