-
Notifications
You must be signed in to change notification settings - Fork 147
feat: create expo config plugin #313
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba48235
feat: create expo config plugin
giautm 4577a49
chore: update README
giautm 6f42800
chore: remove duplicated section
giautm adfbda3
chore: update README
giautm 124a7a5
fix: apply suggestions from code review
giautm 28d243e
fix: fixed plugin imports
giautm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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("./plugin/build/withReactNativeFbads"); | ||
|
giautm marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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,80 @@ | ||
| import { | ||
| AndroidConfig, | ||
| ConfigPlugin, | ||
| createRunOncePlugin, | ||
| withAndroidManifest, | ||
| } from '@expo/config-plugins'; | ||
| const { getMainApplicationOrThrow, prefixAndroidKeys } = AndroidConfig.Manifest; | ||
|
|
||
| const INTERSTITIAL_AD_ACTIVITY = 'com.facebook.ads.InterstitialAdActivity'; | ||
|
|
||
| export const withFacebookManifest: ConfigPlugin = (config) => { | ||
| return withAndroidManifest(config, (config) => { | ||
| config.modResults = setFacebookConfig(config.modResults); | ||
| return config; | ||
| }); | ||
| }; | ||
|
|
||
| export function setFacebookConfig( | ||
| androidManifest: AndroidConfig.Manifest.AndroidManifest | ||
| ) { | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| let mainApplication = getMainApplicationOrThrow(androidManifest); | ||
| mainApplication = ensureFacebookActivity({ mainApplication }); | ||
|
|
||
| return androidManifest; | ||
| } | ||
|
|
||
| function ensureFacebookActivity({ | ||
| mainApplication, | ||
| }: { | ||
| mainApplication: AndroidConfig.Manifest.ManifestApplication; | ||
| }) { | ||
| if (Array.isArray(mainApplication.activity)) { | ||
| // Remove all Facebook InterstitialAdActivity first | ||
| mainApplication.activity = mainApplication.activity.filter((activity) => { | ||
| return activity.$?.['android:name'] !== INTERSTITIAL_AD_ACTIVITY; | ||
| }); | ||
| } else { | ||
| mainApplication.activity = []; | ||
| } | ||
|
|
||
| mainApplication.activity.push(getFacebookAdActivity()); | ||
| return mainApplication; | ||
| } | ||
|
|
||
| function buildXMLItem({ | ||
| head, | ||
| children, | ||
| }: { | ||
| head: Record<string, string>; | ||
| children?: Record<string, string | any[]>; | ||
| }) { | ||
| return { ...(children ?? {}), $: head }; | ||
| } | ||
|
|
||
| function getFacebookAdActivity() { | ||
| /** | ||
| <activity | ||
| android:name="com.facebook.ads.InterstitialAdActivity" | ||
| android:configChanges="keyboardHidden|orientation" | ||
| /> | ||
| */ | ||
| return buildXMLItem({ | ||
| head: prefixAndroidKeys({ | ||
| name: INTERSTITIAL_AD_ACTIVITY, | ||
| configChanges: 'keyboardHidden|orientation', | ||
| }), | ||
| }) as AndroidConfig.Manifest.ManifestActivity; | ||
| } | ||
|
|
||
| /** | ||
| * Apply react-native-fbads configuration for Expo SDK 44 projects. | ||
| */ | ||
| const withReactNativeFbads: ConfigPlugin = (config) => { | ||
| return withFacebookManifest(config); | ||
| }; | ||
|
|
||
| const pkg = require('react-native-fbads/package.json'); | ||
|
|
||
| export default createRunOncePlugin(withReactNativeFbads, pkg.name, pkg.version); |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "extends": "expo-module-scripts/tsconfig.plugin", | ||
| "compilerOptions": { | ||
| "outDir": "./build" | ||
| }, | ||
| "include": ["./src"], | ||
| "exclude": ["**/__mocks__/*", "**/__tests__/*"] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.