mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
51e8e0b7e1
Summary:
This adds support for `<Picker style={}/>` prop for text styling. It reuses most of conversion logic from BaseText. This means that it actually supports more styles than Paper Picker supported. (Paper picker only supported ~4 styles, this supports everything that Text supports, so 10+ styles).
The only tricky thing is that Picker supports multiple ways of setting text color. Both
<Picker
itemStyle={{color: '#008BD0'}} >
<Picker.Item label="Java" value="java" />
<Picker.Item label="JavaScript" value="js" />
</Picker>
and
<Picker>
<Picker.Item label="Java" value="java" color={'#008BD0'} />
<Picker.Item label="JavaScript" value="js" />
</Picker>
technically work in Paper. I've decided to maintain this behaviour (since there's lots of product code callsites to both options).
Changelog: [iOS][Fabric] Fabric Picker support
Reviewed By: sammy-SC
Differential Revision: D23980319
fbshipit-source-id: e469a837e28af0ad97cf0e171df26ee19adff3ab
47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "PickerProps.h"
|
|
|
|
#include <react/renderer/attributedstring/conversions.h>
|
|
#include <react/renderer/components/iospicker/conversions.h>
|
|
#include <react/renderer/core/propsConversions.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
PickerProps::PickerProps(
|
|
PickerProps const &sourceProps,
|
|
RawProps const &rawProps)
|
|
: ViewProps(sourceProps, rawProps),
|
|
BaseTextProps(sourceProps, rawProps),
|
|
items(convertRawProp(rawProps, "items", sourceProps.items, {})),
|
|
selectedIndex(convertRawProp(
|
|
rawProps,
|
|
"selectedIndex",
|
|
sourceProps.selectedIndex,
|
|
{0})),
|
|
testID(convertRawProp(rawProps, "testID", sourceProps.testID, {})),
|
|
accessibilityLabel(convertRawProp(
|
|
rawProps,
|
|
"accessibilityLabel",
|
|
sourceProps.accessibilityLabel,
|
|
{})){
|
|
|
|
};
|
|
|
|
TextAttributes PickerProps::getEffectiveTextAttributes() const {
|
|
auto result = TextAttributes::defaultTextAttributes();
|
|
// Default is left aligned, but Picker wants default to be center aligned.
|
|
result.alignment = TextAlignment::Center;
|
|
result.apply(textAttributes);
|
|
return result;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|