2015-03-23 23:28:42 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 23:28:42 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-03-23 23:28:42 +03:00
|
|
|
*/
|
2015-03-13 20:45:27 +03:00
|
|
|
|
CocoaPods frameworks compatibility: Step 2 (#25619)
Summary:
This is my proposal for fixing `use_frameworks!` compatibility without breaking all `<React/*>` imports I outlined in https://github.com/facebook/react-native/pull/25393#issuecomment-508457700. If accepted, it will fix https://github.com/facebook/react-native/issues/25349.
It builds on the changes I made in https://github.com/facebook/react-native/pull/25496 by ensuring each podspec has a unique value for `header_dir` so that framework imports do not conflict. Every podspec which should be included in the `<React/*>` namespace now includes it's headers from `React-Core.podspec`.
The following pods can still be imported with `<React/*>` and so should not have breaking changes: `React-ART`,`React-DevSupport`, `React-CoreModules`, `React-RCTActionSheet`, `React-RCTAnimation`, `React-RCTBlob`, `React-RCTImage`, `React-RCTLinking`, `React-RCTNetwork`, `React-RCTPushNotification`, `React-RCTSettings`, `React-RCTText`, `React-RCTSettings`, `React-RCTVibration`, `React-RCTWebSocket` .
There are still a few breaking changes which I hope will be acceptable:
- `React-Core.podspec` has been moved to the root of the project. Any `Podfile` that references it will need to update the path.
- ~~`React-turbomodule-core`'s headers now live under `<turbomodule/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-turbomodulesamples`'s headers now live under `<turbomodulesamples/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-TypeSaferty`'s headers now live under `<TypeSafety/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511040967.
- ~~`React-jscallinvoker`'s headers now live under `<jscallinvoker/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- Each podspec now uses `s.static_framework = true`. This means that a minimum of CocoaPods 1.5 ([released in April 2018](http://blog.cocoapods.org/CocoaPods-1.5.0/)) is now required. This is needed so that the ` __has_include` conditions can still work when frameworks are enabled.
Still to do:
- ~~Including `React-turbomodule-core` with `use_frameworks!` enabled causes the C++ import failures we saw in https://github.com/facebook/react-native/issues/25349. I'm sure it will be possible to fix this but I need to dig deeper (perhaps a custom modulemap would be needed).~~ Addressed by https://github.com/facebook/react-native/pull/25619/commits/33573511f02f3502a28bad48e085e9a4b8608302.
- I haven't got Fabric working yet. I wonder if it would be acceptable to move Fabric out of the `<React/*>` namespace since it is new? �
## Changelog
[iOS] [Fixed] - Fixed compatibility with CocoaPods frameworks.
Pull Request resolved: https://github.com/facebook/react-native/pull/25619
Test Plan:
### FB
```
buck build catalyst
```
### Sample Project
Everything should work exactly as before, where `use_frameworks!` is not in `Podfile`s. I have a branch on my [sample project](https://github.com/jtreanor/react-native-cocoapods-frameworks) here which has `use_frameworks!` in its `Podfile` to demonstrate this is fixed.
You can see that it works with these steps:
1. `git clone git@github.com:jtreanor/react-native-cocoapods-frameworks.git`
2. `git checkout fix-frameworks-subspecs`
3. `cd ios && pod install`
4. `cd .. && react-native run-ios`
The sample app will build and run successfully. To see that it still works without frameworks, remove `use_frameworks!` from the `Podfile` and do steps 3 and 4 again.
### RNTesterPods
`RNTesterPodsPods` can now work with or without `use_frameworks!`.
1. Go to the `RNTester` directory and run `pod install`.
2. Run the tests in `RNTesterPods.xcworkspace` to see that everything still works fine.
3. Uncomment the `use_frameworks!` line at the top of `RNTester/Podfile` and run `pod install` again.
4. Run the tests again and see that it still works with frameworks enabled.
Reviewed By: PeteTheHeat
Differential Revision: D16465247
Pulled By: PeteTheHeat
fbshipit-source-id: cad837e9cced06d30cc5b372af1c65c7780b9e7a
2019-07-25 08:26:42 +03:00
|
|
|
#import <React/RCTActionSheetManager.h>
|
2015-03-13 20:45:27 +03:00
|
|
|
|
2016-11-23 18:47:52 +03:00
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTLog.h>
|
|
|
|
#import <React/RCTUIManager.h>
|
|
|
|
#import <React/RCTUtils.h>
|
2015-03-13 20:45:27 +03:00
|
|
|
|
2015-04-08 18:52:48 +03:00
|
|
|
@interface RCTActionSheetManager () <UIActionSheetDelegate>
|
2015-03-13 20:45:27 +03:00
|
|
|
@end
|
|
|
|
|
2015-04-08 15:42:43 +03:00
|
|
|
@implementation RCTActionSheetManager
|
|
|
|
{
|
2015-10-21 22:19:33 +03:00
|
|
|
// Use NSMapTable, as UIAlertViews do not implement <NSCopying>
|
|
|
|
// which is required for NSDictionary keys
|
|
|
|
NSMapTable *_callbacks;
|
2015-03-13 20:45:27 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 15:42:43 +03:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2016-06-05 02:25:55 +03:00
|
|
|
@synthesize bridge = _bridge;
|
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
- (dispatch_queue_t)methodQueue
|
2015-03-13 20:45:27 +03:00
|
|
|
{
|
2015-10-21 22:19:33 +03:00
|
|
|
return dispatch_get_main_queue();
|
2015-03-13 20:45:27 +03:00
|
|
|
}
|
|
|
|
|
2019-01-05 00:06:03 +03:00
|
|
|
- (void)presentViewController:(UIViewController *)alertController
|
|
|
|
onParentViewController:(UIViewController *)parentViewController
|
|
|
|
anchorViewTag:(NSNumber *)anchorViewTag
|
2015-04-20 22:06:02 +03:00
|
|
|
{
|
2019-01-05 00:06:03 +03:00
|
|
|
alertController.modalPresentationStyle = UIModalPresentationPopover;
|
|
|
|
UIView *sourceView = parentViewController.view;
|
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
if (anchorViewTag) {
|
2019-01-05 00:06:03 +03:00
|
|
|
sourceView = [self.bridge.uiManager viewForReactTag:anchorViewTag];
|
2015-10-21 22:19:33 +03:00
|
|
|
} else {
|
2019-01-05 00:06:03 +03:00
|
|
|
alertController.popoverPresentationController.permittedArrowDirections = 0;
|
2015-10-21 22:19:33 +03:00
|
|
|
}
|
2019-01-05 00:06:03 +03:00
|
|
|
alertController.popoverPresentationController.sourceView = sourceView;
|
|
|
|
alertController.popoverPresentationController.sourceRect = sourceView.bounds;
|
|
|
|
[parentViewController presentViewController:alertController animated:YES completion:nil];
|
2015-04-20 22:06:02 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:52:48 +03:00
|
|
|
RCT_EXPORT_METHOD(showActionSheetWithOptions:(NSDictionary *)options
|
2015-10-21 22:19:33 +03:00
|
|
|
callback:(RCTResponseSenderBlock)callback)
|
2015-03-13 20:45:27 +03:00
|
|
|
{
|
2015-09-22 20:43:56 +03:00
|
|
|
if (RCTRunningInAppExtension()) {
|
|
|
|
RCTLogError(@"Unable to show action sheet from app extension");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-13 20:45:27 +03:00
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
if (!_callbacks) {
|
|
|
|
_callbacks = [NSMapTable strongToStrongObjectsMapTable];
|
2015-04-18 20:43:20 +03:00
|
|
|
}
|
2015-03-13 20:45:27 +03:00
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
NSString *title = [RCTConvert NSString:options[@"title"]];
|
2016-03-31 08:10:00 +03:00
|
|
|
NSString *message = [RCTConvert NSString:options[@"message"]];
|
2015-11-04 01:45:46 +03:00
|
|
|
NSArray<NSString *> *buttons = [RCTConvert NSStringArray:options[@"options"]];
|
2015-10-21 22:19:33 +03:00
|
|
|
NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1;
|
Feature/action sheet destructive button indexes (#18254)
Summary:
This is a recreation of #13924, rebased on top of master, as the former PR wasn't re-reviewed and automatically closed by the bot.
iOS [Action Sheets docs](https://developer.apple.com/ios/human-interface-guidelines/ui-views/action-sheets/) say
> Make destructive choices prominent. Use red for buttons that perform destructive or dangerous actions, and display these buttons at the top of an action sheet.
Currently ActionSheetIOS's showActionSheetWithOptions only supports a single destructive button via the prop `destructiveButtonIndex`.
This PR maintains backwards compatibility with `destructiveButtonIndex` while simultaneously supporting `destructiveButtonIndexes` allowing developers to pass an array of destructive indexes
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 1],
}, () => {});
```
<img width="282" alt="actionsheet" src="https://cloud.githubusercontent.com/assets/3091143/25963211/1c211a16-3646-11e7-9b7c-c9a2dbea7832.png">
Some additional tests, all working as expected (item only red if it is a matching index).
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 19],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: undefined,
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 5, 0, 0],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 5, 0, 0, 'non numeric', 12.34],
}, () => {});
```
The following will crash the app but I believe this is expected
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: 'not an array',
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: null,
}, () => {});
```
- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.
Pull Request resolved: https://github.com/facebook/react-native/pull/18254
Differential Revision: D13680516
Pulled By: hramos
fbshipit-source-id: ac183cdcf5e1daef8e3c584dcf6a921bbecad475
2019-01-24 23:03:00 +03:00
|
|
|
NSArray<NSNumber *> *destructiveButtonIndices;
|
|
|
|
if ([options[@"destructiveButtonIndex"] isKindOfClass:[NSArray class]]) {
|
|
|
|
destructiveButtonIndices = [RCTConvert NSArray:options[@"destructiveButtonIndex"]];
|
|
|
|
} else {
|
|
|
|
NSNumber *destructiveButtonIndex = options[@"destructiveButtonIndex"] ? [RCTConvert NSNumber:options[@"destructiveButtonIndex"]] : @-1;
|
|
|
|
destructiveButtonIndices = @[destructiveButtonIndex];
|
|
|
|
}
|
2015-10-21 22:19:33 +03:00
|
|
|
|
2016-05-21 03:03:34 +03:00
|
|
|
UIViewController *controller = RCTPresentedViewController();
|
2016-04-06 19:20:39 +03:00
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
if (controller == nil) {
|
|
|
|
RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options);
|
|
|
|
return;
|
2015-04-18 20:43:20 +03:00
|
|
|
}
|
2015-03-13 20:45:27 +03:00
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
/*
|
|
|
|
* The `anchor` option takes a view to set as the anchor for the share
|
|
|
|
* popup to point to, on iPads running iOS 8. If it is not passed, it
|
|
|
|
* defaults to centering the share popup on screen without any arrows.
|
|
|
|
*/
|
|
|
|
NSNumber *anchorViewTag = [RCTConvert NSNumber:options[@"anchor"]];
|
2019-01-05 00:06:03 +03:00
|
|
|
|
2016-09-02 05:37:54 +03:00
|
|
|
UIAlertController *alertController =
|
|
|
|
[UIAlertController alertControllerWithTitle:title
|
|
|
|
message:message
|
|
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
|
|
|
NSInteger index = 0;
|
|
|
|
for (NSString *option in buttons) {
|
|
|
|
UIAlertActionStyle style = UIAlertActionStyleDefault;
|
Feature/action sheet destructive button indexes (#18254)
Summary:
This is a recreation of #13924, rebased on top of master, as the former PR wasn't re-reviewed and automatically closed by the bot.
iOS [Action Sheets docs](https://developer.apple.com/ios/human-interface-guidelines/ui-views/action-sheets/) say
> Make destructive choices prominent. Use red for buttons that perform destructive or dangerous actions, and display these buttons at the top of an action sheet.
Currently ActionSheetIOS's showActionSheetWithOptions only supports a single destructive button via the prop `destructiveButtonIndex`.
This PR maintains backwards compatibility with `destructiveButtonIndex` while simultaneously supporting `destructiveButtonIndexes` allowing developers to pass an array of destructive indexes
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 1],
}, () => {});
```
<img width="282" alt="actionsheet" src="https://cloud.githubusercontent.com/assets/3091143/25963211/1c211a16-3646-11e7-9b7c-c9a2dbea7832.png">
Some additional tests, all working as expected (item only red if it is a matching index).
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 19],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: undefined,
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 5, 0, 0],
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: [0, 5, 0, 0, 'non numeric', 12.34],
}, () => {});
```
The following will crash the app but I believe this is expected
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: 'not an array',
}, () => {});
```
```js
ActionSheetIOS.showActionSheetWithOptions({
options: ['one', 'two', 'three'],
destructiveButtonIndexes: null,
}, () => {});
```
- [x] Explain the **motivation** for making this change.
- [x] Provide a **test plan** demonstrating that the code is solid.
- [x] Match the **code formatting** of the rest of the codebase.
- [x] Target the `master` branch, NOT a "stable" branch.
Pull Request resolved: https://github.com/facebook/react-native/pull/18254
Differential Revision: D13680516
Pulled By: hramos
fbshipit-source-id: ac183cdcf5e1daef8e3c584dcf6a921bbecad475
2019-01-24 23:03:00 +03:00
|
|
|
if ([destructiveButtonIndices containsObject:@(index)]) {
|
2016-09-02 05:37:54 +03:00
|
|
|
style = UIAlertActionStyleDestructive;
|
|
|
|
} else if (index == cancelButtonIndex) {
|
|
|
|
style = UIAlertActionStyleCancel;
|
2015-10-21 22:19:33 +03:00
|
|
|
}
|
|
|
|
|
2016-09-02 05:37:54 +03:00
|
|
|
NSInteger localIndex = index;
|
|
|
|
[alertController addAction:[UIAlertAction actionWithTitle:option
|
|
|
|
style:style
|
|
|
|
handler:^(__unused UIAlertAction *action){
|
|
|
|
callback(@[@(localIndex)]);
|
|
|
|
}]];
|
2015-10-21 22:19:33 +03:00
|
|
|
|
2016-09-02 05:37:54 +03:00
|
|
|
index++;
|
|
|
|
}
|
2015-12-09 16:08:36 +03:00
|
|
|
|
2016-09-02 05:37:54 +03:00
|
|
|
alertController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]];
|
2019-01-05 00:06:03 +03:00
|
|
|
[self presentViewController:alertController onParentViewController:controller anchorViewTag:anchorViewTag];
|
2015-03-13 20:45:27 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:52:48 +03:00
|
|
|
RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options
|
2015-10-21 22:19:33 +03:00
|
|
|
failureCallback:(RCTResponseErrorBlock)failureCallback
|
2015-04-08 18:52:48 +03:00
|
|
|
successCallback:(RCTResponseSenderBlock)successCallback)
|
2015-03-13 20:45:27 +03:00
|
|
|
{
|
2015-10-21 22:19:33 +03:00
|
|
|
if (RCTRunningInAppExtension()) {
|
|
|
|
RCTLogError(@"Unable to show action sheet from app extension");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-22 16:33:31 +03:00
|
|
|
NSMutableArray<id> *items = [NSMutableArray array];
|
2015-08-05 02:18:44 +03:00
|
|
|
NSString *message = [RCTConvert NSString:options[@"message"]];
|
|
|
|
if (message) {
|
2015-04-18 20:43:20 +03:00
|
|
|
[items addObject:message];
|
|
|
|
}
|
2017-12-11 21:37:14 +03:00
|
|
|
NSURL *URL = [RCTConvert NSURL:options[@"url"]];
|
|
|
|
if (URL) {
|
|
|
|
if ([URL.scheme.lowercaseString isEqualToString:@"data"]) {
|
2016-02-22 16:33:31 +03:00
|
|
|
NSError *error;
|
2017-12-11 21:37:14 +03:00
|
|
|
NSData *data = [NSData dataWithContentsOfURL:URL
|
2016-02-22 16:33:31 +03:00
|
|
|
options:(NSDataReadingOptions)0
|
|
|
|
error:&error];
|
|
|
|
if (!data) {
|
|
|
|
failureCallback(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[items addObject:data];
|
|
|
|
} else {
|
2017-12-11 21:37:14 +03:00
|
|
|
[items addObject:URL];
|
2016-02-22 16:33:31 +03:00
|
|
|
}
|
2015-04-18 20:43:20 +03:00
|
|
|
}
|
2017-12-11 21:37:14 +03:00
|
|
|
if (items.count == 0) {
|
|
|
|
RCTLogError(@"No `url` or `message` to share");
|
|
|
|
return;
|
|
|
|
}
|
2015-09-22 20:43:56 +03:00
|
|
|
|
2015-10-21 22:19:33 +03:00
|
|
|
UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
|
2015-11-19 19:40:47 +03:00
|
|
|
|
|
|
|
NSString *subject = [RCTConvert NSString:options[@"subject"]];
|
|
|
|
if (subject) {
|
|
|
|
[shareController setValue:subject forKey:@"subject"];
|
|
|
|
}
|
|
|
|
|
2015-11-30 17:18:55 +03:00
|
|
|
NSArray *excludedActivityTypes = [RCTConvert NSStringArray:options[@"excludedActivityTypes"]];
|
|
|
|
if (excludedActivityTypes) {
|
|
|
|
shareController.excludedActivityTypes = excludedActivityTypes;
|
|
|
|
}
|
|
|
|
|
2016-05-21 03:03:34 +03:00
|
|
|
UIViewController *controller = RCTPresentedViewController();
|
2016-09-02 05:37:54 +03:00
|
|
|
shareController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, __unused NSArray *returnedItems, NSError *activityError) {
|
|
|
|
if (activityError) {
|
|
|
|
failureCallback(activityError);
|
|
|
|
} else {
|
2015-06-15 17:53:45 +03:00
|
|
|
successCallback(@[@(completed), RCTNullIfNil(activityType)]);
|
2015-09-15 21:28:24 +03:00
|
|
|
}
|
2016-09-02 05:37:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NSNumber *anchorViewTag = [RCTConvert NSNumber:options[@"anchor"]];
|
2015-12-09 16:08:36 +03:00
|
|
|
shareController.view.tintColor = [RCTConvert UIColor:options[@"tintColor"]];
|
2019-01-05 00:06:03 +03:00
|
|
|
|
|
|
|
[self presentViewController:shareController onParentViewController:controller anchorViewTag:anchorViewTag];
|
2015-03-13 20:45:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|