mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove Picker from OSS (#31772)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/31772 Changelog:[General][Removed] - Remove Picker iOS code Reviewed By: p-sun Differential Revision: D29124724 fbshipit-source-id: d3b3a409961cf04e2cd079a91986d30e3166dcda
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0b40fea60c
commit
cddb97ad18
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <React/RCTViewComponentView.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* UIView class for root <Picker> component.
|
||||
*/
|
||||
@interface RCTPickerComponentView : RCTViewComponentView
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTPickerComponentView.h"
|
||||
|
||||
#import <React/RCTConvert.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <react/renderer/components/iospicker/PickerComponentDescriptor.h>
|
||||
#import <react/renderer/components/iospicker/PickerEventEmitter.h>
|
||||
#import <react/renderer/components/iospicker/PickerProps.h>
|
||||
#import <react/renderer/textlayoutmanager/RCTAttributedTextUtils.h>
|
||||
|
||||
#import "RCTConversions.h"
|
||||
#import "RCTFabricComponentsPlugins.h"
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
@interface RCTPickerComponentView () <UIPickerViewAccessibilityDelegate, UIPickerViewDelegate, UIPickerViewDataSource>
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTPickerComponentView {
|
||||
UIPickerView *_pickerView;
|
||||
std::vector<PickerItemsStruct> _items;
|
||||
NSInteger _selectedIndex;
|
||||
NSString *_accessibilityLabel;
|
||||
NSDictionary<NSAttributedStringKey, id> *_textAttributes;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
_pickerView = [[UIPickerView alloc] initWithFrame:self.bounds];
|
||||
self.contentView = _pickerView;
|
||||
[self setPropsToDefault];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setPropsToDefault
|
||||
{
|
||||
static const auto defaultProps = std::make_shared<const PickerProps>();
|
||||
_props = defaultProps;
|
||||
_pickerView.delegate = self;
|
||||
_pickerView.dataSource = self;
|
||||
_selectedIndex = NSNotFound;
|
||||
NSMutableParagraphStyle *const paragraphStyle = [NSMutableParagraphStyle new];
|
||||
paragraphStyle.alignment = NSTextAlignmentCenter;
|
||||
_textAttributes = @{
|
||||
NSForegroundColorAttributeName : [UIColor blackColor],
|
||||
NSFontAttributeName : [UIFont systemFontOfSize:21],
|
||||
NSParagraphStyleAttributeName : paragraphStyle
|
||||
};
|
||||
}
|
||||
|
||||
- (void)prepareForRecycle
|
||||
{
|
||||
[super prepareForRecycle];
|
||||
_selectedIndex = NSNotFound;
|
||||
}
|
||||
|
||||
#pragma mark - RCTComponentViewProtocol
|
||||
|
||||
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
||||
{
|
||||
return concreteComponentDescriptorProvider<PickerComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldPickerProps = *std::static_pointer_cast<const PickerProps>(_props);
|
||||
const auto &newPickerProps = *std::static_pointer_cast<const PickerProps>(props);
|
||||
bool needsToReload = false;
|
||||
|
||||
if (oldPickerProps.items != newPickerProps.items) {
|
||||
_items = newPickerProps.items;
|
||||
needsToReload = true;
|
||||
}
|
||||
|
||||
if (oldPickerProps.selectedIndex != newPickerProps.selectedIndex) {
|
||||
_selectedIndex = newPickerProps.selectedIndex;
|
||||
[self setSelectedIndex];
|
||||
}
|
||||
|
||||
if (oldPickerProps.textAttributes != newPickerProps.textAttributes) {
|
||||
_textAttributes = RCTNSTextAttributesFromTextAttributes(newPickerProps.getEffectiveTextAttributes());
|
||||
needsToReload = true;
|
||||
}
|
||||
|
||||
// TODO (T75217510) - Figure out testID.
|
||||
if (oldPickerProps.testID != newPickerProps.testID) {
|
||||
}
|
||||
|
||||
if (oldPickerProps.accessibilityLabel != newPickerProps.accessibilityLabel) {
|
||||
_accessibilityLabel = [NSString stringWithUTF8String:newPickerProps.accessibilityLabel.c_str()];
|
||||
}
|
||||
|
||||
if (needsToReload) {
|
||||
[_pickerView reloadAllComponents];
|
||||
}
|
||||
|
||||
[super updateProps:props oldProps:oldProps];
|
||||
}
|
||||
|
||||
#pragma mark - Native Commands
|
||||
|
||||
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
|
||||
{
|
||||
if ([commandName isEqualToString:@"setNativeSelectedIndex"] && [args objectAtIndex:0]) {
|
||||
NSNumber *selectedIndex = [args objectAtIndex:0];
|
||||
if (_selectedIndex != selectedIndex.integerValue) {
|
||||
[self setSelectedIndex];
|
||||
}
|
||||
} else {
|
||||
RCTLogWarn(@"Attempting to send unknown command to Picker component: %@", commandName);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSelectedIndex
|
||||
{
|
||||
BOOL animated = _selectedIndex != NSNotFound; // Don't animate the initial value.
|
||||
[_pickerView selectRow:_selectedIndex inComponent:0 animated:animated];
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewDataSource protocol
|
||||
|
||||
- (NSInteger)numberOfComponentsInPickerView:(__unused UIPickerView *)pickerView
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)pickerView:(__unused UIPickerView *)pickerView numberOfRowsInComponent:(__unused NSInteger)component
|
||||
{
|
||||
return _items.size();
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewDelegate methods
|
||||
|
||||
- (NSString *)pickerView:(__unused UIPickerView *)pickerView
|
||||
titleForRow:(NSInteger)row
|
||||
forComponent:(__unused NSInteger)component
|
||||
{
|
||||
return [NSString stringWithUTF8String:_items[row].label.c_str()];
|
||||
}
|
||||
|
||||
- (CGFloat)pickerView:(__unused UIPickerView *)pickerView rowHeightForComponent:(NSInteger)__unused component
|
||||
{
|
||||
return ((UIFont *)_textAttributes[NSFontAttributeName]).pointSize + 19;
|
||||
}
|
||||
|
||||
- (UIView *)pickerView:(UIPickerView *)pickerView
|
||||
viewForRow:(NSInteger)row
|
||||
forComponent:(NSInteger)component
|
||||
reusingView:(UILabel *)label
|
||||
{
|
||||
if (!label) {
|
||||
label = [[UILabel alloc] initWithFrame:(CGRect){
|
||||
CGPointZero,
|
||||
{
|
||||
[pickerView rowSizeForComponent:component].width,
|
||||
[pickerView rowSizeForComponent:component].height,
|
||||
}}];
|
||||
}
|
||||
NSMutableDictionary<NSAttributedStringKey, id> *attributes = [_textAttributes mutableCopy];
|
||||
// Color can be passed in from <Picker style={}/> or from <Picker.Item color={}/>
|
||||
// If Picker.Item color is set, use that. Else fall back to Picker style (with black as default).
|
||||
if (RCTUIColorFromSharedColor(_items[row].textColor)) {
|
||||
attributes[NSForegroundColorAttributeName] = RCTUIColorFromSharedColor(_items[row].textColor);
|
||||
}
|
||||
label.attributedText = [[NSAttributedString alloc] initWithString:[self pickerView:pickerView
|
||||
titleForRow:row
|
||||
forComponent:component]
|
||||
attributes:attributes];
|
||||
return label;
|
||||
}
|
||||
|
||||
- (void)pickerView:(__unused UIPickerView *)pickerView
|
||||
didSelectRow:(NSInteger)row
|
||||
inComponent:(__unused NSInteger)component
|
||||
{
|
||||
_selectedIndex = row;
|
||||
PickerEventEmitter::PickerIOSChangeEvent event = {.newValue = _items[row].value, .newIndex = (int)row};
|
||||
if (_eventEmitter) {
|
||||
std::static_pointer_cast<PickerEventEmitter const>(_eventEmitter)->onChange(event);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewAccessibilityDelegate protocol
|
||||
|
||||
- (NSString *)pickerView:(UIPickerView *)pickerView accessibilityLabelForComponent:(NSInteger)component
|
||||
{
|
||||
return _accessibilityLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Class<RCTComponentViewProtocol> RCTPickerCls(void)
|
||||
{
|
||||
return RCTPickerComponentView.class;
|
||||
}
|
||||
@@ -35,7 +35,6 @@ Class<RCTComponentViewProtocol> RCTPullToRefreshViewCls(void) __attribute__((use
|
||||
Class<RCTComponentViewProtocol> RCTActivityIndicatorViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTSliderCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTSwitchCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTPickerCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTUnimplementedNativeViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTParagraphCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTTextInputCls(void) __attribute__((used));
|
||||
|
||||
@@ -24,7 +24,6 @@ Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name) {
|
||||
{"ActivityIndicatorView", RCTActivityIndicatorViewCls},
|
||||
{"Slider", RCTSliderCls},
|
||||
{"Switch", RCTSwitchCls},
|
||||
{"Picker", RCTPickerCls},
|
||||
{"UnimplementedNativeView", RCTUnimplementedNativeViewCls},
|
||||
{"Paragraph", RCTParagraphCls},
|
||||
{"TextInput", RCTTextInputCls},
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/UIView+React.h>
|
||||
|
||||
@interface RCTPicker : UIPickerView
|
||||
|
||||
@property (nonatomic, copy) NSArray<NSDictionary *> *items;
|
||||
@property (nonatomic, assign) NSInteger selectedIndex;
|
||||
|
||||
@property (nonatomic, strong) UIColor *color;
|
||||
@property (nonatomic, strong) UIFont *font;
|
||||
@property (nonatomic, assign) NSTextAlignment textAlign;
|
||||
|
||||
@property (nonatomic, copy) RCTBubblingEventBlock onChange;
|
||||
|
||||
@end
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTPicker.h"
|
||||
|
||||
#import "RCTConvert.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
@interface RCTPicker () <UIPickerViewDataSource, UIPickerViewDelegate, UIPickerViewAccessibilityDelegate>
|
||||
@end
|
||||
|
||||
@implementation RCTPicker
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if ((self = [super initWithFrame:frame])) {
|
||||
_color = [UIColor blackColor];
|
||||
_font = [UIFont systemFontOfSize:21]; // TODO: selected title default should be 23.5
|
||||
_selectedIndex = NSNotFound;
|
||||
_textAlign = NSTextAlignmentCenter;
|
||||
self.delegate = self;
|
||||
[self selectRow:0 inComponent:0
|
||||
animated:
|
||||
YES]; // Workaround for missing selection indicator lines (see
|
||||
// https://stackoverflow.com/questions/39564660/uipickerview-selection-indicator-not-visible-in-ios10)
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
|
||||
|
||||
- (void)setItems:(NSArray<NSDictionary *> *)items
|
||||
{
|
||||
_items = [items copy];
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)setSelectedIndex:(NSInteger)selectedIndex
|
||||
{
|
||||
if (_selectedIndex != selectedIndex) {
|
||||
BOOL animated = _selectedIndex != NSNotFound; // Don't animate the initial value
|
||||
_selectedIndex = selectedIndex;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self selectRow:selectedIndex inComponent:0 animated:animated];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewDataSource protocol
|
||||
|
||||
- (NSInteger)numberOfComponentsInPickerView:(__unused UIPickerView *)pickerView
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)pickerView:(__unused UIPickerView *)pickerView numberOfRowsInComponent:(__unused NSInteger)component
|
||||
{
|
||||
return _items.count;
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewDelegate methods
|
||||
|
||||
- (NSString *)pickerView:(__unused UIPickerView *)pickerView
|
||||
titleForRow:(NSInteger)row
|
||||
forComponent:(__unused NSInteger)component
|
||||
{
|
||||
return [RCTConvert NSString:_items[row][@"label"]];
|
||||
}
|
||||
|
||||
- (CGFloat)pickerView:(__unused UIPickerView *)pickerView rowHeightForComponent:(NSInteger)__unused component
|
||||
{
|
||||
return _font.pointSize + 19;
|
||||
}
|
||||
|
||||
- (UIView *)pickerView:(UIPickerView *)pickerView
|
||||
viewForRow:(NSInteger)row
|
||||
forComponent:(NSInteger)component
|
||||
reusingView:(UILabel *)label
|
||||
{
|
||||
if (!label) {
|
||||
label = [[UILabel alloc] initWithFrame:(CGRect){
|
||||
CGPointZero,
|
||||
{
|
||||
[pickerView rowSizeForComponent:component].width,
|
||||
[pickerView rowSizeForComponent:component].height,
|
||||
}}];
|
||||
}
|
||||
|
||||
label.font = _font;
|
||||
|
||||
label.textColor = [RCTConvert UIColor:_items[row][@"textColor"]] ?: _color;
|
||||
|
||||
label.textAlignment = _textAlign;
|
||||
label.text = [self pickerView:pickerView titleForRow:row forComponent:component];
|
||||
return label;
|
||||
}
|
||||
|
||||
- (void)pickerView:(__unused UIPickerView *)pickerView
|
||||
didSelectRow:(NSInteger)row
|
||||
inComponent:(__unused NSInteger)component
|
||||
{
|
||||
_selectedIndex = row;
|
||||
if (_onChange && _items.count > (NSUInteger)row) {
|
||||
_onChange(@{
|
||||
@"newIndex" : @(row),
|
||||
@"newValue" : RCTNullIfNil(_items[row][@"value"]),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewAccessibilityDelegate protocol
|
||||
|
||||
- (NSString *)pickerView:(UIPickerView *)pickerView accessibilityLabelForComponent:(NSInteger)component
|
||||
{
|
||||
return super.accessibilityLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import <React/RCTViewManager.h>
|
||||
|
||||
@interface RCTPickerManager : RCTViewManager
|
||||
|
||||
@end
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#import "RCTPickerManager.h"
|
||||
|
||||
#import <React/RCTUIManager.h>
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTFont.h"
|
||||
#import "RCTPicker.h"
|
||||
|
||||
@implementation RCTPickerManager
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
return [RCTPicker new];
|
||||
}
|
||||
|
||||
RCT_EXPORT_VIEW_PROPERTY(items, NSArray<NSDictionary *>)
|
||||
RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger)
|
||||
RCT_REMAP_VIEW_PROPERTY(accessibilityLabel, reactAccessibilityElement.accessibilityLabel, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
||||
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
|
||||
RCT_EXPORT_VIEW_PROPERTY(textAlign, NSTextAlignment)
|
||||
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTPicker)
|
||||
{
|
||||
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
|
||||
}
|
||||
RCT_CUSTOM_VIEW_PROPERTY(fontWeight, NSString, __unused RCTPicker)
|
||||
{
|
||||
view.font = [RCTFont updateFont:view.font withWeight:json]; // defaults to normal
|
||||
}
|
||||
RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSString, __unused RCTPicker)
|
||||
{
|
||||
view.font = [RCTFont updateFont:view.font withStyle:json]; // defaults to normal
|
||||
}
|
||||
RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTPicker)
|
||||
{
|
||||
view.font = [RCTFont updateFont:view.font withFamily:json ?: defaultView.font.familyName];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(setNativeSelectedIndex : (nonnull NSNumber *)viewTag toIndex : (nonnull NSNumber *)index)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
||||
UIView *view = viewRegistry[viewTag];
|
||||
if ([view isKindOfClass:[RCTPicker class]]) {
|
||||
[(RCTPicker *)view setSelectedIndex:index.integerValue];
|
||||
} else {
|
||||
RCTLogError(@"View type must be RCTPicker!");
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -147,15 +147,6 @@ Pod::Spec.new do |s|
|
||||
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
|
||||
end
|
||||
|
||||
ss.subspec "picker" do |sss|
|
||||
sss.dependency folly_dep_name, folly_version
|
||||
sss.compiler_flags = folly_compiler_flags
|
||||
sss.source_files = "react/renderer/components/picker/iospicker/**/*.{m,mm,cpp,h}"
|
||||
sss.exclude_files = "react/renderer/components/picker/iospicker/tests"
|
||||
sss.header_dir = "react/renderer/components/iospicker"
|
||||
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/RCT-Folly\"" }
|
||||
end
|
||||
|
||||
ss.subspec "rncore" do |sss|
|
||||
sss.dependency folly_dep_name, folly_version
|
||||
sss.compiler_flags = folly_compiler_flags
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
load(
|
||||
"//tools/build_defs/oss:rn_defs.bzl",
|
||||
"ANDROID",
|
||||
"APPLE",
|
||||
"CXX",
|
||||
"YOGA_CXX_TARGET",
|
||||
"get_apple_compiler_flags",
|
||||
"get_apple_inspector_flags",
|
||||
"get_preprocessor_flags_for_build_mode",
|
||||
"react_native_xplat_target",
|
||||
"rn_xplat_cxx_library",
|
||||
"subdir_glob",
|
||||
)
|
||||
|
||||
APPLE_COMPILER_FLAGS = get_apple_compiler_flags()
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "iospicker",
|
||||
srcs = glob(
|
||||
["**/*.cpp"],
|
||||
),
|
||||
headers = glob(
|
||||
["**/*.h"],
|
||||
),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob(
|
||||
[
|
||||
("", "*.h"),
|
||||
],
|
||||
prefix = "react/renderer/components/iospicker",
|
||||
),
|
||||
compiler_flags = [
|
||||
"-fexceptions",
|
||||
"-frtti",
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
],
|
||||
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
|
||||
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
|
||||
force_static = True,
|
||||
labels = ["supermodule:xplat/default/public.react_native.infra"],
|
||||
platforms = (ANDROID, APPLE, CXX),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"//xplat/folly:headers_only",
|
||||
YOGA_CXX_TARGET,
|
||||
react_native_xplat_target("react/debug:debug"),
|
||||
react_native_xplat_target("react/utils:utils"),
|
||||
react_native_xplat_target("react/renderer/attributedstring:attributedstring"),
|
||||
react_native_xplat_target("react/renderer/core:core"),
|
||||
react_native_xplat_target("react/renderer/graphics:graphics"),
|
||||
react_native_xplat_target("react/renderer/components/text:text"),
|
||||
react_native_xplat_target("react/renderer/components/view:view"),
|
||||
],
|
||||
)
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/iospicker/PickerShadowNode.h>
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
|
||||
/*
|
||||
* Descriptor for <Picker> component.
|
||||
*/
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class PickerComponentDescriptor final
|
||||
: public ConcreteComponentDescriptor<PickerShadowNode> {
|
||||
public:
|
||||
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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 "PickerEventEmitter.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void PickerEventEmitter::onChange(PickerIOSChangeEvent event) const {
|
||||
dispatchEvent("change", [event = std::move(event)](jsi::Runtime &runtime) {
|
||||
auto payload = jsi::Object(runtime);
|
||||
payload.setProperty(runtime, "newValue", event.newValue);
|
||||
payload.setProperty(runtime, "newIndex", event.newIndex);
|
||||
return payload;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/view/ViewEventEmitter.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class PickerEventEmitter : public ViewEventEmitter {
|
||||
public:
|
||||
using ViewEventEmitter::ViewEventEmitter;
|
||||
|
||||
struct PickerIOSChangeEvent {
|
||||
std::string newValue;
|
||||
int newIndex;
|
||||
};
|
||||
|
||||
void onChange(PickerIOSChangeEvent event) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/iospicker/primitives.h>
|
||||
#include <react/renderer/components/text/BaseTextProps.h>
|
||||
#include <react/renderer/components/view/ViewProps.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class PickerProps final : public ViewProps, public BaseTextProps {
|
||||
public:
|
||||
PickerProps() = default;
|
||||
PickerProps(PickerProps const &sourceProps, RawProps const &rawProps);
|
||||
|
||||
#pragma mark - Props
|
||||
|
||||
std::vector<PickerItemsStruct> items{};
|
||||
int selectedIndex{0};
|
||||
std::string const testID{};
|
||||
std::string const accessibilityLabel{};
|
||||
|
||||
#pragma mark - Accessors
|
||||
TextAttributes getEffectiveTextAttributes() const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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 "PickerShadowNode.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
extern const char PickerComponentName[] = "Picker";
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/iospicker/PickerEventEmitter.h>
|
||||
#include <react/renderer/components/iospicker/PickerProps.h>
|
||||
#include <react/renderer/components/iospicker/PickerState.h>
|
||||
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
extern const char PickerComponentName[];
|
||||
|
||||
/*
|
||||
* `ShadowNode` for <Picker> component.
|
||||
*/
|
||||
class PickerShadowNode final : public ConcreteViewShadowNode<
|
||||
PickerComponentName,
|
||||
PickerProps,
|
||||
PickerEventEmitter,
|
||||
PickerState> {
|
||||
public:
|
||||
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/*
|
||||
* State for <Picker> component.
|
||||
*/
|
||||
class PickerState final {};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/debug/react_native_assert.h>
|
||||
#include <react/renderer/components/iospicker/primitives.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
inline void fromRawValue(
|
||||
const RawValue &value,
|
||||
std::vector<PickerItemsStruct> &items) {
|
||||
react_native_assert(value.hasType<std::vector<RawValue>>());
|
||||
auto array = (std::vector<RawValue>)value;
|
||||
items.reserve(array.size());
|
||||
|
||||
for (auto const &val : array) {
|
||||
bool check = val.hasType<better::map<std::string, RawValue>>();
|
||||
react_native_assert(check);
|
||||
auto map = (better::map<std::string, RawValue>)val;
|
||||
PickerItemsStruct item;
|
||||
|
||||
if (map.find("label") != map.end()) {
|
||||
react_native_assert(map.at("label").hasType<std::string>());
|
||||
item.label = (std::string)map.at("label");
|
||||
}
|
||||
if (map.find("value") != map.end()) {
|
||||
react_native_assert(map.at("value").hasType<std::string>());
|
||||
item.value = (std::string)map.at("value");
|
||||
}
|
||||
if (map.find("textColor") != map.end()) {
|
||||
react_native_assert(map.at("textColor").hasType<int>());
|
||||
item.textColor = (int)map.at("textColor");
|
||||
}
|
||||
items.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
struct PickerItemsStruct {
|
||||
std::string label;
|
||||
std::string value;
|
||||
SharedColor textColor;
|
||||
|
||||
bool operator==(const PickerItemsStruct &rhs) const {
|
||||
return (
|
||||
label == rhs.label && value == rhs.value && textColor == rhs.textColor);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -341,7 +341,6 @@ PODS:
|
||||
- React-Fabric/components/inputaccessory (= 1000.0.0)
|
||||
- React-Fabric/components/legacyviewmanagerinterop (= 1000.0.0)
|
||||
- React-Fabric/components/modal (= 1000.0.0)
|
||||
- React-Fabric/components/picker (= 1000.0.0)
|
||||
- React-Fabric/components/rncore (= 1000.0.0)
|
||||
- React-Fabric/components/root (= 1000.0.0)
|
||||
- React-Fabric/components/safeareaview (= 1000.0.0)
|
||||
@@ -395,14 +394,6 @@ PODS:
|
||||
- React-jsi (= 1000.0.0)
|
||||
- React-jsiexecutor (= 1000.0.0)
|
||||
- ReactCommon/turbomodule/core (= 1000.0.0)
|
||||
- React-Fabric/components/picker (1000.0.0):
|
||||
- RCT-Folly/Fabric (= 2021.04.26.00)
|
||||
- RCTRequired (= 1000.0.0)
|
||||
- RCTTypeSafety (= 1000.0.0)
|
||||
- React-graphics (= 1000.0.0)
|
||||
- React-jsi (= 1000.0.0)
|
||||
- React-jsiexecutor (= 1000.0.0)
|
||||
- ReactCommon/turbomodule/core (= 1000.0.0)
|
||||
- React-Fabric/components/rncore (1000.0.0):
|
||||
- RCT-Folly/Fabric (= 2021.04.26.00)
|
||||
- RCTRequired (= 1000.0.0)
|
||||
@@ -885,7 +876,7 @@ SPEC CHECKSUMS:
|
||||
React-Core: f5b65410a2ecdbb4560f23dc4525588390b0b3b1
|
||||
React-CoreModules: 818e75a3eb8f431be8fc3d8c8eb15206b3f52e81
|
||||
React-cxxreact: fa0884110d142f7e1600a86ae769d5fd43ec8a69
|
||||
React-Fabric: ee21f85af985320ca427353e95821a5b4d6f4f46
|
||||
React-Fabric: f31c68913f46481d01e09a6f44a5a6bc8664cfdd
|
||||
React-graphics: 57cb7ea16c092a9953c96549a29b49d5e207c25c
|
||||
React-jsi: 93fc7d193c0499a9b10157655e6f1e755f67b3d0
|
||||
React-jsiexecutor: 1e995bed2de8965703917c562fe35ec023a68ae5
|
||||
|
||||
Reference in New Issue
Block a user