forked from stripe/stripe-terminal-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: create expo plugin * chore: add plugin params * chore: add expo docs * fix package.json path
- Loading branch information
1 parent
993e833
commit 928bd49
Showing
5 changed files
with
247 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/commonjs/plugin/withStripeTerminal'); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
ConfigPlugin, | ||
createRunOncePlugin, | ||
IOSConfig, | ||
withInfoPlist, | ||
} from '@expo/config-plugins'; | ||
|
||
const pkg = require('stripe-terminal-react-native/package.json'); | ||
|
||
type StripeTerminalPluginProps = { | ||
bluetoothBackgroundMode?: boolean; | ||
locationWhenInUsePermission?: string; | ||
bluetoothPeripheralPermission?: string; | ||
bluetoothAlwaysUsagePermission?: string; | ||
}; | ||
|
||
const withStripeTerminal: ConfigPlugin<StripeTerminalPluginProps> = ( | ||
config, | ||
props | ||
) => { | ||
config = withStripeTerminalIos(config, props); | ||
config = withNoopSwiftFile(config); | ||
|
||
return config; | ||
}; | ||
|
||
/** | ||
* Grant bluetooth and location permissions. | ||
*/ | ||
const withStripeTerminalIos: ConfigPlugin<StripeTerminalPluginProps> = ( | ||
expoConfig, | ||
props | ||
) => { | ||
return withInfoPlist(expoConfig, (config) => { | ||
if (props.bluetoothBackgroundMode) { | ||
config.modResults.UIBackgroundModes = ['bluetooth-central']; | ||
} | ||
|
||
config.modResults.NSLocationWhenInUseUsageDescription = | ||
props.locationWhenInUsePermission || | ||
'Location access is required in order to accept payments.'; | ||
|
||
config.modResults.NSBluetoothPeripheralUsageDescription = | ||
props.bluetoothPeripheralPermission || | ||
'Bluetooth access is required in order to connect to supported bluetooth card readers.'; | ||
|
||
config.modResults.NSBluetoothAlwaysUsageDescription = | ||
props.bluetoothAlwaysUsagePermission || | ||
'This app uses Bluetooth to connect to supported card readers.'; | ||
return config; | ||
}); | ||
}; | ||
|
||
/** | ||
* Add a blank Swift file to the Xcode project for Swift compatibility. | ||
*/ | ||
export const withNoopSwiftFile: ConfigPlugin = (config) => { | ||
return IOSConfig.XcodeProjectFile.withBuildSourceFile(config, { | ||
filePath: 'noop-file.swift', | ||
contents: [ | ||
'//', | ||
'// @generated', | ||
'// A blank Swift file must be created for native modules with Swift files to work correctly.', | ||
'//', | ||
'', | ||
].join('\n'), | ||
}); | ||
}; | ||
|
||
export default createRunOncePlugin(withStripeTerminal, pkg.name, pkg.version); |
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