Skip to content

fix(config-plugin): Improve plugin to support swift #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Titozzz
Copy link

@Titozzz Titozzz commented Apr 14, 2025

#276 is a good start but it's not enough.

Comment on lines +100 to +131
stringContents = isSwift
? mergeContents({
src: stringContents,
newSrc: 'import intercom_react_native.IntercomModule',
comment: '//',
tag: 'Intercom header',
anchor: /import Expo/,
offset: 1,
}).contents
: addObjcImports(stringContents, ['<IntercomModule.h>']);

// Remove previous code
stringContents = stringContents.replace(
/\s*\[IntercomModule initialize:@"(.*)" withAppId:@"(.*)"];/g,
''
);

stringContents = insertContentsInsideObjcFunctionBlock(
stringContents,
'application didFinishLaunchingWithOptions:',
`[IntercomModule initialize:@"${props.iosApiKey}" withAppId:@"${props.appId}"];`,
{ position: 'tailBeforeLastReturn' }
);
stringContents = stringContents
.replace(
/\s*\[IntercomModule initialize:@"(.*)" withAppId:@"(.*)"];/g,
''
)
.replace(/\s*IntercomModule\.initialize\((.*), withAppId: (.*)\)/g, '');

stringContents = isSwift
? insertContentsInsideSwiftFunctionBlock(
stringContents,
'application(_:didFinishLaunchingWithOptions:)',
`IntercomModule.initialize("${props.iosApiKey}", withAppId: "${props.appId}")`,
{ position: 'tailBeforeLastReturn' }
)
: insertContentsInsideObjcFunctionBlock(
stringContents,
'application didFinishLaunchingWithOptions:',
`[IntercomModule initialize:@"${props.iosApiKey}" withAppId:@"${props.appId}"];`,
{ position: 'tailBeforeLastReturn' }
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

artistic choice ,but I would have a big if-else instead, so it's easier to see what is for Swift and what is for objc :D

...
} else {
...
}

@Nasseratic
Copy link

Nasseratic commented Apr 22, 2025

@Titozzz Thanks a lot for the PR, hope the intercome team will merge this soon :)

@mzaien
Copy link

mzaien commented Apr 28, 2025

@Br1an-Boyle @liutingdu can you review this pr ? it is almost time for sdk 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants