Last active
March 21, 2024 13:12
-
-
Save wcastand/1d70b0044cd78eeeea60f418ea121b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
"./plugins/intercom.plugin.js", | |
{ | |
iosApiKey: "ios key", | |
androidApiKey: "android key", | |
appId: "app id", | |
} | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createRunOncePlugin, withAppDelegate, AndroidConfig, withMainApplication } = require("@expo/config-plugins") | |
const { addImports, appendContentsInsideDeclarationBlock } = require("@expo/config-plugins/build/android/codeMod") | |
const { addObjcImports, insertContentsInsideObjcFunctionBlock } = require("@expo/config-plugins/build/ios/codeMod") | |
const mainApplication = (_config, props) => | |
withMainApplication(_config, (config) => { | |
let stringContents = config.modResults.contents | |
stringContents = addImports(stringContents, ["com.intercom.reactnative.IntercomModule;"], false) | |
stringContents = appendContentsInsideDeclarationBlock( | |
stringContents, | |
"onCreate", | |
`IntercomModule.initialize(this, "${props.androidApiKey}", "${props.appId}");`, | |
) | |
config.modResults.contents = stringContents | |
return config | |
}) | |
const androidManifest = (_config) => | |
AndroidConfig.Permissions.withPermissions( | |
_config, | |
["android.permission.READ_EXTERNAL_STORAGE", "android.permission.VIBRATE"].filter(Boolean), | |
) | |
const withIntercomAndroid = (config, props) => { | |
let newConfig = config | |
newConfig = mainApplication(newConfig, props) | |
newConfig = androidManifest(newConfig) | |
return newConfig | |
} | |
const appDelegate = (_config, props) => | |
withAppDelegate(_config, (config) => { | |
let stringContents = config.modResults.contents | |
stringContents = addObjcImports(stringContents, ["<IntercomModule.h>"]) | |
stringContents = insertContentsInsideObjcFunctionBlock( | |
stringContents, | |
"application didFinishLaunchingWithOptions:", | |
`[IntercomModule initialize:@"${props.iosApiKey}" withAppId:@"${props.appId}"];`, | |
{ position: "tailBeforeLastReturn" }, | |
) | |
config.modResults.contents = stringContents | |
return config | |
}) | |
const withIntercomIOS = (config, props) => appDelegate(config, props) | |
const withIntercom = (config, props) => { | |
let newConfig = config | |
newConfig = withIntercomAndroid(newConfig, props) | |
newConfig = withIntercomIOS(newConfig, props) | |
return newConfig | |
} | |
module.exports = createRunOncePlugin(withIntercom, "intercom-plugin", "1.0.0") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment