Advertisement
Guest User

Untitled

a guest
Oct 26th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [items addObject:[RCTDevMenuItem buttonItemWithTitleBlock:^NSString *{
  2.     return @"Change packager location";
  3.   } handler:^{
  4.     UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Change packager location"
  5.                                                                               message: @"Input packager IP and port"
  6.                                                                        preferredStyle:UIAlertControllerStyleAlert];
  7.     [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  8.       textField.placeholder = @"0.0.0.0";
  9.       textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  10.       textField.borderStyle = UITextBorderStyleRoundedRect;
  11.     }];
  12.     [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  13.       textField.placeholder = @"8081";
  14.       textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  15.       textField.borderStyle = UITextBorderStyleRoundedRect;
  16.     }];
  17.     [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(__unused UIAlertAction *action) {
  18.       NSArray * textfields = alertController.textFields;
  19.       UITextField * ip = textfields[0];
  20.       UITextField * port = textfields[1];
  21.       NSURLComponents *components = [NSURLComponents componentsWithURL:self->_bridge.bundleURL resolvingAgainstBaseURL:YES];
  22.       NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
  23.       formatter.numberStyle = NSNumberFormatterDecimalStyle;
  24.       NSNumber *portNumber = [formatter numberFromString:port.text];
  25.       if (portNumber == nil) portNumber = [NSNumber numberWithInt: 8081];
  26.       components.scheme = @"http";
  27.       components.host = ip.text;
  28.       components.port = portNumber;
  29.       components.path = @"/index.bundle";
  30.       components.query = @"platform=ios&dev=true&hot=true";
  31.       self->_bridge.bundleURL = components.URL;
  32.       [self->_bridge reload];
  33.     }]];
  34.     [RCTPresentedViewController() presentViewController:alertController animated:YES completion:NULL];
  35.   }]];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement