Skip to content

Commit 900fd9d

Browse files
authored
Merge pull request #148 from xmartlabs/dependencies-update
[Fix] Bring back Expo plugin
2 parents 0d4393f + 4ea50de commit 900fd9d

15 files changed

+800
-19
lines changed

README.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Line SDK wrapper for React Native 🚀
3535
"useFrameworks": "static" // This is required
3636
}
3737
}
38-
]
38+
],
39+
"@xmartlabs/react-native-line"
3940
]
4041
```
4142

@@ -57,6 +58,39 @@ Line SDK wrapper for React Native 🚀
5758
cd ios && pod install
5859
```
5960

61+
3. Change your `AppDelegate.m` to match the following:
62+
63+
```objectivec
64+
#import "RNLine-Swift.h"
65+
66+
...
67+
68+
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
69+
{
70+
return [LineLogin application:application open:url options:options];
71+
}
72+
```
73+
74+
4. Insert the following snippet in your `Info.plist` to match the [LINE documentation](https://developers.line.biz/en/docs/line-login-sdks/ios-sdk/swift/setting-up-project/#config-infoplist-file):
75+
76+
```xml
77+
<key>CFBundleURLTypes</key>
78+
<array>
79+
<dict>
80+
<key>CFBundleTypeRole</key>
81+
<string>Editor</string>
82+
<key>CFBundleURLSchemes</key>
83+
<array>
84+
<string>line3rdp.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
85+
</array>
86+
</dict>
87+
</array>
88+
<key>LSApplicationQueriesSchemes</key>
89+
<array>
90+
<string>lineauth2</string>
91+
</array>
92+
```
93+
6094
## Usage
6195

6296
1. Import the `LineLogin` module:
@@ -69,14 +103,14 @@ Line SDK wrapper for React Native 🚀
69103

70104
```typescript
71105
useEffect(() => {
72-
LineLogin.setup('YOUR_CHANNEL_ID')
106+
LineLogin.setup({ channelId: 'YOUR_CHANNEL_ID' })
73107
}, [])
74108
```
75109

76110
3. Login with the `login` method:
77111

78112
```typescript
79-
LineLogin.login({})
113+
LineLogin.login()
80114
```
81115

82116
## API

android/src/main/java/com/xmartlabs/rnline/LineLogin.kt

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class LineLogin(private val reactContext: ReactApplicationContext) :
3030
ReactContextBaseJavaModule(reactContext) {
3131
companion object {
3232
private const val MODULE_NAME: String = "LineLogin"
33-
private const val ERROR_MESSAGE: String = "ERROR"
3433
}
3534

3635
private lateinit var channelId: String
@@ -43,13 +42,12 @@ class LineLogin(private val reactContext: ReactApplicationContext) :
4342
override fun getName() = MODULE_NAME
4443

4544
@ReactMethod
46-
fun setup(channelId: String, promise: Promise) {
45+
fun setup(args: ReadableMap, promise: Promise) {
4746
val context: Context = reactContext.applicationContext
48-
this.channelId = channelId
49-
this.lineApiClient = LineApiClientBuilder(context, channelId).build()
47+
channelId = args.getString("channelId")!!
48+
lineApiClient = LineApiClientBuilder(context, channelId).build()
5049
reactContext.addActivityEventListener(object : ActivityEventListener {
5150
override fun onNewIntent(intent: Intent?) {}
52-
5351
override fun onActivityResult(
5452
activity: Activity?,
5553
requestCode: Int,
@@ -118,7 +116,7 @@ class LineLogin(private val reactContext: ReactApplicationContext) :
118116
@ReactMethod
119117
fun getProfile(promise: Promise) {
120118
uiCoroutineScope.launch {
121-
val lineApiResponse = withContext(Dispatchers.IO) { lineApiClient.profile }
119+
val lineApiResponse = withContext(Dispatchers.IO) { lineApiClient.getProfile() }
122120
if (!lineApiResponse.isSuccess) {
123121
promise.reject(
124122
lineApiResponse.responseCode.name,
@@ -137,7 +135,7 @@ class LineLogin(private val reactContext: ReactApplicationContext) :
137135
if (resultCode != Activity.RESULT_OK || intent == null) {
138136
loginResult?.reject(
139137
resultCode.toString(),
140-
ERROR_MESSAGE,
138+
"ERROR",
141139
null
142140
)
143141
}

app.plugin.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./plugin/withLineSDK')

example/app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"resizeMode": "contain",
4343
"backgroundColor": "#ffffff"
4444
}
45-
]
45+
],
46+
"@xmartlabs/react-native-line"
4647
],
4748
"experiments": {
4849
"typedRoutes": true

example/app/_layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function () {
2323

2424
useEffect(() => {
2525
if (loaded) {
26-
Line.setup('2006826760')
26+
Line.setup({ channelId: '2006826760' })
2727
SplashScreen.hideAsync()
2828
}
2929
}, [loaded])

example/package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/LineLogin.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#import "React/RCTBridgeModule.h"
33

44
@interface RCT_EXTERN_MODULE(LineLogin, NSObject)
5-
RCT_EXTERN_METHOD(setup: (NSString *)channelId
5+
RCT_EXTERN_METHOD(setup: (NSDictionary *)arguments
66
resolver: (RCTPromiseResolveBlock)resolve
77
rejecter: (RCTPromiseRejectBlock)reject
88
)

ios/LineLogin.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ import LineSDK
1919
return LoginManager.shared.application(application, open: userActivity.webpageURL)
2020
}
2121

22-
@objc func setup(_ channelId: String, resolver resolve: @escaping RCTPromiseResolveBlock,
22+
@objc func setup(_ arguments: NSDictionary, resolver resolve: @escaping RCTPromiseResolveBlock,
2323
rejecter reject: @escaping RCTPromiseRejectBlock) {
24-
return LoginManager.shared.setup(channelID: channelId, universalLinkURL: nil)
24+
25+
guard let channelID = arguments["channelId"] as? String else {
26+
reject("INVALID_ARGUMENTS", "Missing required argument: channelId", nil)
27+
return
28+
}
29+
30+
let universalLinkURL: URL? = (arguments["universalLinkUrl"] as? String).flatMap { URL(string: $0) }
31+
32+
return LoginManager.shared.setup(channelID: channelID, universalLinkURL: universalLinkURL)
2533
}
2634

2735
@objc func login(_ arguments: NSDictionary?, resolver resolve: @escaping RCTPromiseResolveBlock,
@@ -34,7 +42,7 @@ import LineSDK
3442

3543
let scopes = (args["scopes"] as? [String])?.map { LoginPermission(rawValue: $0) } ?? [.profile]
3644
let onlyWebLogin = (args["onlyWebLogin"] as? Bool) ?? false
37-
var parameters: LoginManager.Parameters = LoginManager.Parameters.init()
45+
var parameters = LoginManager.Parameters.init()
3846

3947
if onlyWebLogin { parameters.onlyWebLogin = onlyWebLogin }
4048

0 commit comments

Comments
 (0)