react-native-navigation的迁移库

RNNUIBarButtonItem.m 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #import <Foundation/Foundation.h>
  2. #import <UIKit/UIKit.h>
  3. #import "RNNUIBarButtonItem.h"
  4. #import "RCTConvert+UIBarButtonSystemItem.h"
  5. @implementation RNNUIBarButtonItem
  6. -(instancetype)init:(NSString*)buttonId withIcon:(UIImage*)iconImage {
  7. UIButton* button = [[UIButton alloc] init];
  8. [button addTarget:self action:@selector(onButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  9. [button setImage:iconImage forState:UIControlStateNormal];
  10. self = [super initWithCustomView:button];
  11. self.buttonId = buttonId;
  12. return self;
  13. }
  14. -(instancetype)init:(NSString*)buttonId withTitle:(NSString*)title {
  15. self = [super initWithTitle:title style:UIBarButtonItemStylePlain target:nil action:nil];
  16. self.buttonId = buttonId;
  17. return self;
  18. }
  19. -(instancetype)init:(NSString*)buttonId withCustomView:(RCTRootView *)reactView {
  20. self = [super initWithCustomView:reactView];
  21. reactView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  22. reactView.delegate = self;
  23. reactView.backgroundColor = [UIColor clearColor];
  24. self.buttonId = buttonId;
  25. return self;
  26. }
  27. -(instancetype)init:(NSString*)buttonId withSystemItem:(NSString *)systemItemName {
  28. UIBarButtonSystemItem systemItem = [RCTConvert UIBarButtonSystemItem:systemItemName];
  29. self = [super initWithBarButtonSystemItem:systemItem target:nil action:nil];
  30. self.buttonId = buttonId;
  31. return self;
  32. }
  33. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  34. CGSize size = rootView.intrinsicContentSize;
  35. rootView.frame = CGRectMake(0, 0, size.width, size.height);
  36. self.width = size.width;
  37. }
  38. - (void)onButtonPressed {
  39. [self.target performSelector:self.action
  40. withObject:self
  41. afterDelay:0];
  42. }
  43. @end