Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
react-native-social
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wind.wang
react-native-social
Commits
32fa2e2d
Commit
32fa2e2d
authored
Feb 25, 2019
by
wind.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add shareImg
parent
d1f5b37f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
153 additions
and
44 deletions
+153
-44
ReactShareModule.java
...id/src/main/java/com/rnsocial/share/ReactShareModule.java
+33
-0
Share.java
android/src/main/java/com/rnsocial/share/Share.java
+87
-43
RNSocialNativeBridgeManager.m
ios/clazz/RNSocialNativeBridgeManager.m
+7
-0
RNShareConfig.h
ios/clazz/share/RNShareConfig.h
+1
-0
RNShareConfig.m
ios/clazz/share/RNShareConfig.m
+25
-1
No files found.
android/src/main/java/com/rnsocial/share/ReactShareModule.java
View file @
32fa2e2d
...
@@ -61,6 +61,39 @@ public class ReactShareModule extends ReactContextBaseJavaModule {
...
@@ -61,6 +61,39 @@ public class ReactShareModule extends ReactContextBaseJavaModule {
}
}
}
}
@ReactMethod
public
void
shareImg
(
final
ReadableMap
params
,
final
Callback
callback
){
final
Activity
activity
=
getCurrentActivity
();
if
(
params
==
null
){
Toast
.
makeText
(
activity
,
"分享参数异常"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
if
(
activity
!=
null
){
activity
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
Share
.
shareImg
(
activity
,
params
,
new
ShareListener
()
{
@Override
public
void
onResult
(
boolean
success
,
String
result
,
Throwable
throwable
)
{
if
(
callback
==
null
){
return
;
}
WritableMap
resultMap
=
Arguments
.
createMap
();
resultMap
.
putBoolean
(
"success"
,
success
);
resultMap
.
putString
(
"message"
,
result
);
callback
.
invoke
(
resultMap
);
}
});
}
catch
(
Exception
e
){
Log
.
e
(
REACT_NAME
,
e
.
getMessage
());
}
}
});
}
}
private
ShareContent
getShareContent
(
ReadableMap
params
){
private
ShareContent
getShareContent
(
ReadableMap
params
){
ShareContent
shareContent
=
new
ShareContent
();
ShareContent
shareContent
=
new
ShareContent
();
if
(
params
.
hasKey
(
"title"
)){
if
(
params
.
hasKey
(
"title"
)){
...
...
android/src/main/java/com/rnsocial/share/Share.java
View file @
32fa2e2d
...
@@ -2,8 +2,12 @@ package com.rnsocial.share;
...
@@ -2,8 +2,12 @@ package com.rnsocial.share;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.Color
;
import
android.graphics.Color
;
import
android.util.Base64
;
import
com.facebook.react.bridge.ReadableMap
;
import
com.rnsocial.SocialConfig
;
import
com.rnsocial.SocialConfig
;
import
com.umeng.socialize.ShareAction
;
import
com.umeng.socialize.ShareAction
;
import
com.umeng.socialize.UMShareAPI
;
import
com.umeng.socialize.UMShareAPI
;
...
@@ -16,6 +20,7 @@ import com.umeng.socialize.shareboard.ShareBoardConfig;
...
@@ -16,6 +20,7 @@ import com.umeng.socialize.shareboard.ShareBoardConfig;
import
com.umeng.socialize.shareboard.SnsPlatform
;
import
com.umeng.socialize.shareboard.SnsPlatform
;
import
com.umeng.socialize.utils.ShareBoardlistener
;
import
com.umeng.socialize.utils.ShareBoardlistener
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -64,55 +69,94 @@ public class Share {
...
@@ -64,55 +69,94 @@ public class Share {
ShareAction
sa
=
new
ShareAction
(
mContext
);
ShareAction
sa
=
new
ShareAction
(
mContext
);
sa
.
setDisplayList
(
getShareMedias
());
sa
.
setDisplayList
(
getShareMedias
());
if
(
content
.
showPoster
)
{
if
(
content
.
showPoster
)
{
sa
.
addButton
(
"生成海报"
,
"umeng_sharebutton_poster"
,
"poster_icon"
,
"poster_icon"
);
// 自定义按钮
sa
.
addButton
(
"生成海报"
,
"umeng_sharebutton_poster"
,
"poster_icon"
,
"poster_icon"
);
// 自定义按钮
}
}
// sa.setDisplayList(getShareMedias());
// sa.setDisplayList(getShareMedias());
sa
.
setShareboardclickCallback
(
new
ShareBoardlistener
()
{
sa
.
setShareboardclickCallback
(
new
ShareBoardlistener
()
{
@Override
@Override
public
void
onclick
(
SnsPlatform
snsPlatform
,
SHARE_MEDIA
share_media
)
{
public
void
onclick
(
SnsPlatform
snsPlatform
,
SHARE_MEDIA
share_media
)
{
if
(
share_media
==
null
)
{
//根据key来区分自定义按钮的类型,并进行对应的操作
if
(
snsPlatform
.
mKeyword
.
equals
(
"umeng_sharebutton_poster"
))
{
listener
.
onResult
(
true
,
"createPoster"
,
null
);
return
;
}
}
String
resultTitle
=
content
.
useContentTitle
&&
(
share_media
==
SHARE_MEDIA
.
WEIXIN_CIRCLE
)
?
content
.
content
:
content
.
title
;
UMWeb
web
=
new
UMWeb
(
content
.
url
);
UMImage
img
=
new
UMImage
(
mContext
,
content
.
image
);
img
.
compressStyle
=
UMImage
.
CompressStyle
.
SCALE
;
web
.
setDescription
(
content
.
content
);
web
.
setTitle
(
resultTitle
);
web
.
setThumb
(
img
);
new
ShareAction
(
mContext
).
setPlatform
(
share_media
)
.
setCallback
(
new
UMShareListener
()
{
@Override
public
void
onStart
(
SHARE_MEDIA
share_media
)
{
}
@Override
public
void
onResult
(
SHARE_MEDIA
share_media
)
{
listener
.
onResult
(
true
,
""
,
null
);
}
@Override
public
void
onError
(
SHARE_MEDIA
share_media
,
Throwable
throwable
)
{
listener
.
onResult
(
false
,
throwable
.
getMessage
(),
throwable
);
}
if
(
share_media
==
null
)
{
@Override
//根据key来区分自定义按钮的类型,并进行对应的操作
public
void
onCancel
(
SHARE_MEDIA
share_media
)
{
if
(
snsPlatform
.
mKeyword
.
equals
(
"umeng_sharebutton_poster"
))
{
Throwable
throwable
=
new
Throwable
(
"取消分享"
);
listener
.
onResult
(
true
,
"createPoster"
,
null
);
listener
.
onResult
(
false
,
"取消分享"
,
throwable
);
return
;
}
}
}
}).
withText
(
content
.
title
)
.
withSubject
(
content
.
content
)
String
resultTitle
=
content
.
useContentTitle
&&
(
share_media
==
SHARE_MEDIA
.
WEIXIN_CIRCLE
)
?
content
.
content
:
content
.
title
;
.
withMedia
(
web
)
UMWeb
web
=
new
UMWeb
(
content
.
url
);
.
share
();
UMImage
img
=
new
UMImage
(
mContext
,
content
.
image
);
}
img
.
compressStyle
=
UMImage
.
CompressStyle
.
SCALE
;
}).
open
(
boardConfig
);
web
.
setDescription
(
content
.
content
);
}
web
.
setTitle
(
resultTitle
);
web
.
setThumb
(
img
);
public
static
void
shareImg
(
final
Activity
mContext
,
final
ReadableMap
params
,
final
ShareListener
listener
)
{
new
ShareAction
(
mContext
).
setPlatform
(
share_media
)
SHARE_MEDIA
share_media
=
params
.
getString
(
"platformType"
).
equals
(
"1"
)?
SHARE_MEDIA
.
WEIXIN
:
SHARE_MEDIA
.
WEIXIN_CIRCLE
;
.
setCallback
(
new
UMShareListener
()
{
// UMImage image = new UMImage(mContext, new File(params.getString("imgPath")));
@Override
String
imgBase64
=
params
.
getString
(
"imgBase64"
);
public
void
onStart
(
SHARE_MEDIA
share_media
)
{
Bitmap
bitmap
=
null
;
}
try
{
byte
[]
bitmapArray
=
Base64
.
decode
(
imgBase64
,
Base64
.
DEFAULT
);
@Override
bitmap
=
BitmapFactory
.
decodeByteArray
(
bitmapArray
,
0
,
bitmapArray
.
length
);
public
void
onResult
(
SHARE_MEDIA
share_media
)
{
}
catch
(
Exception
e
)
{
listener
.
onResult
(
true
,
""
,
null
);
e
.
printStackTrace
();
}
}
UMImage
image
=
new
UMImage
(
mContext
,
bitmap
);
@Override
public
void
onError
(
SHARE_MEDIA
share_media
,
Throwable
throwable
)
{
new
ShareAction
(
mContext
).
setPlatform
(
share_media
)
listener
.
onResult
(
false
,
throwable
.
getMessage
(),
throwable
);
.
setCallback
(
new
UMShareListener
()
{
}
@Override
public
void
onStart
(
SHARE_MEDIA
share_media
)
{
@Override
}
public
void
onCancel
(
SHARE_MEDIA
share_media
)
{
Throwable
throwable
=
new
Throwable
(
"取消分享"
);
@Override
listener
.
onResult
(
false
,
"取消分享"
,
throwable
);
public
void
onResult
(
SHARE_MEDIA
share_media
)
{
}
listener
.
onResult
(
true
,
""
,
null
);
}).
withText
(
content
.
title
)
}
.
withSubject
(
content
.
content
)
.
withMedia
(
web
)
@Override
.
share
();
public
void
onError
(
SHARE_MEDIA
share_media
,
Throwable
throwable
)
{
listener
.
onResult
(
false
,
throwable
.
getMessage
(),
throwable
);
}
@Override
public
void
onCancel
(
SHARE_MEDIA
share_media
)
{
Throwable
throwable
=
new
Throwable
(
"取消分享"
);
listener
.
onResult
(
false
,
"取消分享"
,
throwable
);
}
}
}).
open
(
boardConfig
);
}).
withText
(
"分享"
)
.
withMedia
(
image
)
.
share
();
}
}
}
}
ios/clazz/RNSocialNativeBridgeManager.m
View file @
32fa2e2d
...
@@ -37,6 +37,13 @@ RCT_EXPORT_METHOD(share:(NSDictionary*)params callback:(RCTResponseSenderBlock)c
...
@@ -37,6 +37,13 @@ RCT_EXPORT_METHOD(share:(NSDictionary*)params callback:(RCTResponseSenderBlock)c
}];
}];
}
}
RCT_EXPORT_METHOD
(
shareImg
:
(
NSDictionary
*
)
params
callback
:
(
RCTResponseSenderBlock
)
callback
)
{
[[
RNShareConfig
shareInstance
]
shareImgHandler
:
params
callback
:
^
(
RNShareResponse
*
responseDO
)
{
callback
(@[[
responseDO
serialization
]]);
}];
}
@end
@end
...
...
ios/clazz/share/RNShareConfig.h
View file @
32fa2e2d
...
@@ -35,6 +35,7 @@ typedef void (^RNShareResponseCallback)(RNShareResponse *responseDO);
...
@@ -35,6 +35,7 @@ typedef void (^RNShareResponseCallback)(RNShareResponse *responseDO);
-
(
void
)
enableShareWithumengAppKey
:(
NSString
*
)
umengAppKey
snsNames
:(
NSArray
*
)
snsNames
;
-
(
void
)
enableShareWithumengAppKey
:(
NSString
*
)
umengAppKey
snsNames
:(
NSArray
*
)
snsNames
;
-
(
void
)
shareHandler
:(
NSDictionary
*
)
data
callback
:(
RNShareResponseCallback
)
callback
;
-
(
void
)
shareHandler
:(
NSDictionary
*
)
data
callback
:(
RNShareResponseCallback
)
callback
;
-
(
void
)
shareImgHandler
:(
NSDictionary
*
)
data
callback
:(
RNShareResponseCallback
)
callback
;
-
(
void
)
shareHandler
:(
id
)
data
;
-
(
void
)
shareHandler
:(
id
)
data
;
-
(
void
)
initWechat
:(
NSString
*
)
appKey
appSecret
:(
NSString
*
)
appSecret
redirect
:(
NSString
*
)
redirect
;
-
(
void
)
initWechat
:(
NSString
*
)
appKey
appSecret
:(
NSString
*
)
appSecret
redirect
:(
NSString
*
)
redirect
;
...
...
ios/clazz/share/RNShareConfig.m
View file @
32fa2e2d
...
@@ -86,7 +86,7 @@
...
@@ -86,7 +86,7 @@
[
UMSocialShareUIConfig
shareInstance
].
sharePageScrollViewConfig
.
shareScrollViewBackgroundColor
=
UIColor
.
whiteColor
;
[
UMSocialShareUIConfig
shareInstance
].
sharePageScrollViewConfig
.
shareScrollViewBackgroundColor
=
UIColor
.
whiteColor
;
__weak
typeof
(
self
)
weakSelf
=
self
;
__weak
typeof
(
self
)
weakSelf
=
self
;
// 加入
copy
的操作
// 加入
生成海报
的操作
// @see http://dev.umeng.com/social/ios/进阶文档#6
// @see http://dev.umeng.com/social/ios/进阶文档#6
if
(
shareParam
.
showPoster
)
{
if
(
shareParam
.
showPoster
)
{
[
UMSocialUIManager
addCustomPlatformWithoutFilted
:
UMSocialPlatformType_UserDefine_Begin
+
2
[
UMSocialUIManager
addCustomPlatformWithoutFilted
:
UMSocialPlatformType_UserDefine_Begin
+
2
...
@@ -123,6 +123,30 @@
...
@@ -123,6 +123,30 @@
}];
}];
}
}
-
(
void
)
shareImgHandler
:
(
NSDictionary
*
)
data
callback
:
(
RNShareResponseCallback
)
callback
;{
if
(
callback
){
_callback
=
[
callback
copy
];
}
__weak
typeof
(
self
)
weakSelf
=
self
;
NSInteger
platformType
=
[[
data
objectForKey
:
@"platformType"
]
intValue
];
NSString
*
imgBase64
=
[
data
objectForKey
:
@"imgBase64"
];
NSData
*
imageData
=
[[
NSData
alloc
]
initWithBase64EncodedString
:
imgBase64
options
:
NSDataBase64DecodingIgnoreUnknownCharacters
];
UIImage
*
image
=
[
UIImage
imageWithData
:
imageData
];
//创建分享消息对象
UMSocialMessageObject
*
messageObject
=
[
UMSocialMessageObject
messageObject
];
//创建图片内容对象
UMShareImageObject
*
shareObject
=
[[
UMShareImageObject
alloc
]
init
];
[
shareObject
setShareImage
:
image
];
//分享消息对象设置分享内容对象
messageObject
.
shareObject
=
shareObject
;
//调用分享接口
[[
UMSocialManager
defaultManager
]
shareToPlatform
:
platformType
messageObject
:
messageObject
currentViewController
:
[
RNShareConfig
getRootViewController
]
completion
:^
(
id
result
,
NSError
*
error
)
{
[
weakSelf
shareCallback
:
result
error
:
error
];
}];
}
-
(
void
)
shareCallback
:
(
id
)
result
error
:
(
NSError
*
)
error
{
-
(
void
)
shareCallback
:
(
id
)
result
error
:
(
NSError
*
)
error
{
if
(
!
_callback
){
if
(
!
_callback
){
return
;
return
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment