react-native-message-composer
Advanced tools
+3
| import { NativeModules } from 'react-native'; | ||
| export default NativeModules.RNMessageComposer; |
+2
-1
| { | ||
| "name": "react-native-message-composer", | ||
| "version": "0.0.5", | ||
| "version": "0.1.0", | ||
| "description": "React Native module bridge to iOS MFMessageComposeViewController", | ||
@@ -19,2 +19,3 @@ "main": "index.js", | ||
| "iMessage", | ||
| "attachments", | ||
| "MFMessageComposeViewController", | ||
@@ -21,0 +22,0 @@ "ios", |
+34
-8
@@ -19,4 +19,24 @@ # react-native-message-composer | ||
| messageText - string | ||
| attachments - an array of objects | ||
| presentAnimated - boolean (animate the appearance of the message composer - true by default) | ||
| dismissAnimated - boolean (animate the closing of the message composer - true by default) | ||
| ``` | ||
| attachments array: | ||
| ```js | ||
| [ | ||
| { | ||
| url: 'http://...', // required | ||
| typeIdentifier: 'public.jpeg', // required | ||
| filename: 'pic.jpg', // optional | ||
| } | ||
| ] | ||
| ``` | ||
| The url can be a web url to an image, video etc but be careful as by default http urls will not work without making changes to the info.plist in the native project. The url can also be a file path on the device, you could for example use https://facebook.github.io/react-native/docs/cameraroll.html to retrieve info on photos stored on the device. | ||
| For `typeIdentifier` see https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html | ||
| For further info on attachments view https://developer.apple.com/reference/messageui/mfmessagecomposeviewcontroller/1614069-addattachmentdata | ||
| The following shows an example args object | ||
@@ -29,4 +49,4 @@ | ||
| ], | ||
| 'subject':'Sample message subject', | ||
| 'messageText':'Sample message text' | ||
| 'messageText':'Sample message text', | ||
| 'dismissAnimated': false | ||
| } | ||
@@ -70,6 +90,6 @@ ``` | ||
| ### rnpm | ||
| ### rnpm (react-native link) | ||
| 1. From inside your project run `npm install react-native-message-composer --save` | ||
| 2. run `rnpm link` | ||
| 2. run `react-native link` | ||
@@ -79,5 +99,9 @@ ## Usage Example | ||
| ```js | ||
| var React = require('react-native'); | ||
| var Composer = require('NativeModules').RNMessageComposer; | ||
| import React from 'react'; | ||
| import Composer from 'react-native-message-composer'; | ||
| // old way of accessing module is still supported too although no longer recommended | ||
| // import { NativeModules } from 'react-native'; | ||
| // const Composer = NativeModules.RNMessageComposer; | ||
| Composer.messagingSupported(supported => { | ||
@@ -94,3 +118,5 @@ // do something like change the view based on whether or not messaging is supported | ||
| 'subject':'My Sample Subject', | ||
| 'recipients':['0987654321', '0123456789'] | ||
| 'recipients':['0987654321', '0123456789'], | ||
| 'presentAnimated': true, | ||
| 'dismissAnimated': false | ||
| }, | ||
@@ -121,3 +147,3 @@ (result) => { | ||
| - [ ] Add support for message attachments | ||
| - [x] Add support for message attachments | ||
| - [ ] Fix issue with a second MFMessageComposeViewController seeming to be present if rotate device whilst MFMessageComposeViewController is open | ||
@@ -124,0 +150,0 @@ - [ ] Look at implementing MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification to listen for changes to the MFMessageComposeViewController `canSendText` class method |
@@ -21,2 +21,4 @@ // | ||
| NSMutableArray *composeCallbacks; | ||
| BOOL presentAnimated; | ||
| BOOL dismissAnimated; | ||
| } | ||
@@ -40,2 +42,4 @@ | ||
| composeViews = [[NSMutableArray alloc] init]; | ||
| presentAnimated = YES; | ||
| dismissAnimated = YES; | ||
| } | ||
@@ -117,5 +121,43 @@ return self; | ||
| } | ||
| if(args[@"presentAnimated"]) | ||
| { | ||
| presentAnimated = [RCTConvert BOOL:args[@"presentAnimated"]]; | ||
| } | ||
| if(args[@"dismissAnimated"]) | ||
| { | ||
| dismissAnimated = [RCTConvert BOOL:args[@"dismissAnimated"]]; | ||
| } | ||
| if([MFMessageComposeViewController canSendAttachments]) { | ||
| if(args[@"attachments"]) | ||
| { | ||
| if([args[@"attachments"] isKindOfClass:[NSArray class]]) | ||
| { | ||
| NSArray *attachments = args[@"attachments"]; | ||
| for(id attachment in attachments) | ||
| { | ||
| if([attachment isKindOfClass:[NSDictionary class]]) | ||
| { | ||
| if ([attachment objectForKey:@"url"] && [attachment objectForKey:@"typeIdentifier"]) | ||
| { | ||
| NSURL *url = [NSURL URLWithString:[attachment objectForKey:@"url"]]; | ||
| NSString *typeIdentifier = [attachment objectForKey:@"typeIdentifier"]; | ||
| NSString *filename = [attachment objectForKey:@"filename"]; | ||
| if (![mcvc addAttachmentData:[NSData dataWithContentsOfURL:url] | ||
| typeIdentifier:typeIdentifier | ||
| filename:filename]) { | ||
| NSLog(@"attachment failed to add: %@", attachment); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; | ||
| [vc presentViewController:mcvc animated:YES completion:nil]; | ||
| [vc presentViewController:mcvc animated:presentAnimated completion:nil]; | ||
@@ -149,3 +191,3 @@ [composeViews addObject:mcvc]; | ||
| UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; | ||
| [vc dismissViewControllerAnimated:YES completion:nil]; | ||
| [vc dismissViewControllerAnimated:dismissAnimated completion:nil]; | ||
@@ -152,0 +194,0 @@ [composeViews removeObjectAtIndex:index]; |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
24048
14.69%9
12.5%1
Infinity%150
20.97%