Files
react-native/ReactCommon/react/renderer/components/picker/iospicker/PickerProps.cpp
T
Peter Argany 51e8e0b7e1 Fabric Picker styling support
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
2020-10-13 11:19:29 -07:00

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