2015-03-23 22:07:33 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-03-11 02:11:28 +00:00
|
|
|
|
|
|
|
#import "RCTPickerManager.h"
|
|
|
|
|
|
|
|
#import "RCTBridge.h"
|
|
|
|
#import "RCTPicker.h"
|
2016-08-05 19:29:19 +00:00
|
|
|
#import "RCTFont.h"
|
2015-03-11 02:11:28 +00:00
|
|
|
|
|
|
|
@implementation RCTPickerManager
|
|
|
|
|
2015-04-09 15:46:53 +00:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-03-11 02:11:28 +00:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 12:58:10 +00:00
|
|
|
return [RCTPicker new];
|
2015-03-11 02:11:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 18:09:04 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(items, NSArray<NSDictionary *>)
|
2015-03-26 13:32:01 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger)
|
2015-09-08 10:27:44 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
2015-12-08 15:44:56 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(textAlign, NSTextAlignment)
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontSize, CGFloat, RCTPicker)
|
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
|
2015-12-08 15:44:56 +00:00
|
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontWeight, NSString, __unused RCTPicker)
|
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withWeight:json]; // defaults to normal
|
2015-12-08 15:44:56 +00:00
|
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontStyle, NSString, __unused RCTPicker)
|
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withStyle:json]; // defaults to normal
|
2015-12-08 15:44:56 +00:00
|
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(fontFamily, NSString, RCTPicker)
|
|
|
|
{
|
2016-08-05 19:29:19 +00:00
|
|
|
view.font = [RCTFont updateFont:view.font withFamily:json ?: defaultView.font.familyName];
|
2015-12-08 15:44:56 +00:00
|
|
|
}
|
2015-03-11 02:11:28 +00:00
|
|
|
|
|
|
|
@end
|