Created
October 16, 2019 08:37
-
-
Save koke/6664df7ccfc401a0fdac47b514f7f108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @flow | |
*/ | |
import type { | |
BubblingEventHandler, | |
Double, | |
WithDefault, | |
} from 'react-native/Libraries/Types/CodegenTypes'; | |
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'; | |
import {type NativeComponentType} from 'react-native/Libraries/Utilities/codegenNativeComponent'; | |
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes'; | |
type Event = $ReadOnly<{| | |
value: Double, | |
|}>; | |
type NativeProps = $ReadOnly<{| | |
...ViewProps, | |
// Props | |
autorepeat?: WithDefault<boolean, true>, | |
continuous?: WithDefault<boolean, true>, | |
wraps?: WithDefault<boolean, false>, | |
maximumValue?: WithDefault<Double, 100>, | |
minimumValue?: WithDefault<Double, 0>, | |
stepValue?: WithDefault<Double, 1>, | |
value?: WithDefault<Double, 0>, | |
// Events | |
onValueChange?: ?BubblingEventHandler<Event, 'paperValueChange'>, | |
|}>; | |
export default (codegenNativeComponent<NativeProps>('Stepper', { | |
interfaceOnly: true, | |
paperComponentName: 'RCTStepper', | |
}): NativeComponentType<NativeProps>); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <React/RCTComponent.h> | |
@interface RCTStepper : UIStepper | |
@property (nonatomic, copy) RCTBubblingEventBlock onValueChange; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RCTStepper.h" | |
@implementation RCTStepper | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <React/RCTViewManager.h> | |
@interface RCTStepperManager : RCTViewManager | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RCTStepperManager.h" | |
#import "RCTStepper.h" | |
@implementation RCTStepperManager | |
RCT_EXPORT_MODULE() | |
RCT_EXPORT_VIEW_PROPERTY(autorepeat, BOOL); | |
RCT_EXPORT_VIEW_PROPERTY(continuous, BOOL); | |
RCT_EXPORT_VIEW_PROPERTY(wraps, BOOL); | |
RCT_EXPORT_VIEW_PROPERTY(value, double); | |
RCT_EXPORT_VIEW_PROPERTY(minimumValue, double); | |
RCT_EXPORT_VIEW_PROPERTY(maximumValue, double); | |
RCT_EXPORT_VIEW_PROPERTY(stepValue, double); | |
- (UIView *)view | |
{ | |
RCTStepper *stepper = [RCTStepper new]; | |
[stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; | |
return stepper; | |
} | |
- (void)valueChanged:(RCTStepper *)sender | |
{ | |
double value = sender.value; | |
sender.onValueChange(@{ | |
@"value": @(value), | |
}); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment