Skip to content

Commit ea0d1f8

Browse files
committed
release(social-share): 2.0.3 - make social options explicit only
Note in plugin README closes #81
1 parent 2a00d09 commit ea0d1f8

File tree

6 files changed

+92
-30
lines changed

6 files changed

+92
-30
lines changed

packages/social-share/README.md

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ns plugin add @nativescript/social-share
88

99
To use the social share module you must first `require()` it. After you `require()` the module you have access to its APIs.
1010

11-
``` JavaScript
11+
```JavaScript
1212
// ------------ JavaScript ------------------
1313
var SocialShare = require("@nativescript/social-share");
1414

@@ -22,7 +22,7 @@ import * as SocialShare from "@nativescript/social-share";
2222

2323
The `shareImage()` method expects an [`ImageSource`](http://docs.nativescript.org/ApiReference/image-source/ImageSource.html) object. The code below loads an image from the app and invokes the share widget with it:
2424

25-
``` JavaScript
25+
```JavaScript
2626
// ------------ JavaScript ------------------
2727
var SocialShare = require("@nativescript/social-share");
2828
var imageSourceModule = require("@nativescript/core");
@@ -40,44 +40,111 @@ SocialShare.shareImage(image);
4040

4141
You can optionally provide a second argument to configure the subject on Android:
4242

43-
``` JavaScript
43+
```JavaScript
4444
SocialShare.shareImage(image, "How would you like to share this image?");
4545
```
4646

4747
### shareText(String text, [optional] String subject)
4848

4949
The `shareText()` method expects a simple string:
5050

51-
``` js
52-
SocialShare.shareText("I love NativeScript!");
51+
```js
52+
SocialShare.shareText('I love NativeScript!');
5353
```
5454

5555
Like `shareImage()`, you can optionally pass `shareText()` a second argument to configure the subject on Android:
5656

57-
``` js
58-
SocialShare.shareText("I love NativeScript!", "How would you like to share this text?");
57+
```js
58+
SocialShare.shareText('I love NativeScript!', 'How would you like to share this text?');
5959
```
6060

6161
### shareUrl(String url, String text, [optional] String subject)
6262

6363
The `shareUrl()` method excepts a url and a string.
6464

65-
``` js
66-
SocialShare.shareUrl("https://www.nativescript.org/", "Home of NativeScript");
65+
```js
66+
SocialShare.shareUrl('https://www.nativescript.org/', 'Home of NativeScript');
6767
```
6868

6969
You can optionally pass `shareUrl()` a second argument to configure the subject on Android:
7070

71-
``` js
72-
SocialShare.shareUrl("https://www.nativescript.org/", "Home of NativeScript", "How would you like to share this url?");
71+
```js
72+
SocialShare.shareUrl('https://www.nativescript.org/', 'Home of NativeScript', 'How would you like to share this url?');
73+
```
74+
75+
### shareViaTwitter(text?: string, url?: string): Promise<void>;
76+
77+
Share text or url via Twitter.
78+
79+
/\*\*
80+
81+
- Share via Facebook
82+
- @param {string} text - Text to share with URL.
83+
- @param {string} url - URL to share.
84+
\*/
85+
86+
```js
87+
SocialShare.shareViaTwitter('Home of NativeScript', 'https://www.nativescript.org/');
88+
```
89+
90+
### shareViaFacebook(text?: string, url?: string): Promise<void>;
91+
92+
Share url via Facebook. Note that `text` will usually be suppressed due to Facebook security/abuse prevention, but the url will come through.
93+
94+
```js
95+
SocialShare.shareViaFacebook('Home of NativeScript', 'https://www.nativescript.org/');
96+
```
97+
98+
- **Android Only NOTE**:
99+
100+
If you are already using the Facebook Share SDK in your project you likely do _not_ have to add the following.
101+
102+
If you are not using the sdk explicitly in your project yet, add to your `app.gradle`:
103+
104+
```
105+
dependencies {
106+
implementation 'com.facebook.android:facebook-share:[5,6)'
107+
}
108+
```
109+
110+
- Add a `meta-data` section and `provider` section ot your `AndroidManifest.xml` so it becomes similar to this:
111+
112+
```xml
113+
<?xml version="1.0" encoding="utf-8"?>
114+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
115+
xmlns:tools="http://schemas.android.com/tools"
116+
...>
117+
<application
118+
android:name="com.tns.NativeScriptApplication"
119+
..>
120+
121+
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
122+
123+
<provider android:authorities="com.facebook.app.FacebookContentProvider{your-facebook-appid}"
124+
android:name="com.facebook.FacebookContentProvider"
125+
android:exported="true"
126+
tools:replace="android:authorities"/>
127+
128+
<activity
129+
android:name="com.tns.NativeScriptActivity"
130+
..>
131+
```
132+
133+
- Create a file `facebooklogin.xml` in `App_Resources/Android/src/main/res/values/`. Add this to the file (replace the id):
134+
135+
```xml
136+
<?xml version='1.0' encoding='utf-8'?>
137+
<resources>
138+
<string name="facebook_app_id">126035687816994</string>
139+
</resources>
73140
```
74141

75142
## Tutorials
76143

77144
Looking for some extra help getting social sharing working in your mobile application? Check out these resources:
78145

79-
* [Social Media Sharing in a Vanilla NativeScript Application](https://www.thepolyglotdeveloper.com/2016/03/implement-social-media-sharing-nativescript-app/)
80-
* [Social Media Sharing in a NativeScript with Angular Application](https://www.thepolyglotdeveloper.com/2017/02/social-media-sharing-prompts-nativescript-angular-application/)
146+
- [Social Media Sharing in a Vanilla NativeScript Application](https://www.thepolyglotdeveloper.com/2016/03/implement-social-media-sharing-nativescript-app/)
147+
- [Social Media Sharing in a NativeScript with Angular Application](https://www.thepolyglotdeveloper.com/2017/02/social-media-sharing-prompts-nativescript-angular-application/)
81148

82149
## License
83150

packages/social-share/index.android.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export function shareViaFacebook(text?: string, url?: string): Promise<void> {
111111
if (!activity) {
112112
reject('No activity found.');
113113
} else {
114+
if (typeof (<any>com).facebook === 'undefined' || typeof (<any>com).facebook.CallbackManager === 'undefined' || typeof (<any>com).facebook.share === 'undefined') {
115+
console.error('Please follow usage instructions to add facebook sdk.');
116+
reject();
117+
return;
118+
}
114119
let manager = (<any>com).facebook.CallbackManager.Factory.create();
115120
Application.android.off('activityResult');
116121
Application.android.on('activityResult', (args) => {

packages/social-share/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/social-share",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Social sharing widget handling for NativeScript",
55
"main": "index",
66
"typings": "index.d.ts",

packages/social-share/platforms/android/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@
1010
android:name="android.support.FILE_PROVIDER_PATHS"
1111
android:resource="@xml/provider_paths"/>
1212
</provider>
13-
14-
<provider android:authorities="com.facebook.app.FacebookContentProvider${applicationId}"
15-
android:name="com.facebook.FacebookContentProvider"
16-
android:exported="true"/>
1713
</application>
1814
</manifest>

packages/social-share/platforms/android/include.gradle

Lines changed: 0 additions & 7 deletions
This file was deleted.

tools/assets/App_Resources/Android/app.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Add your native dependencies here:
1+
repositories {
2+
mavenCentral()
3+
}
24

3-
// Uncomment to add recyclerview-v7 dependency
4-
//dependencies {
5-
// compile 'com.android.support:recyclerview-v7:+'
6-
//}
5+
dependencies {
6+
implementation 'com.facebook.android:facebook-share:[5,6)'
7+
}
78

89
android {
910
compileSdkVersion 29

0 commit comments

Comments
 (0)