Skip to content

Commit e0562f8

Browse files
committed
chore: add support for Expo 53 and the swift version of the AppDelegate
1 parent 2e2dbb7 commit e0562f8

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

plugin/ios/withCustomAppDelegate.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,51 @@ const { withAppDelegate } = require('@expo/config-plugins')
22

33
const generateCode = require('@expo/config-plugins/build/utils/generateCode')
44

5+
function selectStrings(language) {
6+
if (language === 'swift') {
7+
return {
8+
import: {
9+
anchor: /import\s+Expo/,
10+
newSrc: 'import react_native_line',
11+
},
12+
return: {
13+
anchor: /return\s+super\.application\(\s*app,\s*open:\s*url,\s*options:\s*options\s*\)\s*\|\|\s*RCTLinkingManager\.application\(\s*app,\s*open:\s*url,\s*options:\s*options\s*\)/,
14+
newSrc: ' return LineLogin.application(app, open: url, options: options)',
15+
offset: 0,
16+
},
17+
}
18+
} else {
19+
return {
20+
import: {
21+
anchor: /#import\s+"AppDelegate\.h"/,
22+
newSrc: '#import "react_native_line-Swift.h"',
23+
},
24+
return: {
25+
anchor: /-\s*\(BOOL\)\s*application:\s*\(UIApplication\s*\*\)\s*application\s+openURL:\s*\(NSURL\s*\*\)\s*url\s+options:\s*\(NSDictionary<UIApplicationOpenURLOptionsKey,\s*id>\s*\*\)\s*options\s*\{/,
26+
newSrc: ' return [LineLogin application:application open:url options:options];',
27+
},
28+
}
29+
}
30+
}
31+
532
function withCustomAppDelegate(config) {
633
return withAppDelegate(config, config => {
34+
const strings = selectStrings(config.modResults.language)
35+
736
const withImport = generateCode.mergeContents({
837
comment: '//',
9-
anchor: /#import "AppDelegate\.h"/,
10-
newSrc: '#import "react_native_line-Swift.h"',
1138
offset: 1,
1239
src: config.modResults.contents,
1340
tag: 'import',
41+
...strings.import,
1442
})
1543

1644
const withOpenUrl = generateCode.mergeContents({
1745
comment: '//',
18-
anchor: /- \(BOOL\)application:\(UIApplication \*\)application openURL:\(NSURL \*\)url options:\(NSDictionary<UIApplicationOpenURLOptionsKey,id> \*\)options {/,
19-
newSrc: 'return [LineLogin application:application open:url options:options];',
2046
offset: 1,
2147
src: withImport.contents,
22-
tag: 'return',
48+
tag: 'linking',
49+
...strings.return,
2350
})
2451

2552
return {

0 commit comments

Comments
 (0)