-
Expo's new config plugin setup would allow React Native Firebase to work with Expo managed. All it would require is creating a simple config plugin. Docs are here: https://docs.expo.io/guides/config-plugins/ I would PR this, but I honestly don't know how native code works so I'm not exactly sure how to implement it. But the gist is, Expo lets you edit native files and configurations in a "prebuild" step. Users can install this as a simple JS plugin in their UpdateThis was added in 12.4.0! See docs. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 21 replies
-
@mikehardy curious what you think. Happy to help however I can. We basically just need to turn the installation instructions into a config plugin, and suddenly any React Native user (including Expo managed apps) can use react-native-firebase. So cool! |
Beta Was this translation helpful? Give feedback.
-
Here's my latest working example (iOS only):
const GoogleServicesInfoPlist = `` // copy the XML file into this string
module.exports = {
GoogleServicesInfoPlist
}
// app.config.ts
import { ExpoConfig } from '@expo/config'
import {
ConfigPlugin,
ExportedConfigWithProps,
WarningAggregator,
withAppDelegate,
withDangerousMod
} from '@expo/config-plugins'
import { resolve } from 'path'
import fs from 'fs'
const config = {
// your expo config
}
/**
* This code will all go inside of the RNFB repo, making it easy for users to import in their projects.
*/
const RN_FIREBASE_IMPORT = `#import <Firebase.h>
`
const RN_FIREBASE_DID_FINISH_LAUNCHING_IDENTIFIER = `- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{`
const RN_FIREBASE_DID_FINISH_LAUNCHING_CODE = `
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}`
function modifyAppDelegate(appDelegate: string) {
if (!appDelegate.includes(RN_FIREBASE_IMPORT)) {
appDelegate = RN_FIREBASE_IMPORT + appDelegate
}
if (appDelegate.includes(RN_FIREBASE_DID_FINISH_LAUNCHING_IDENTIFIER)) {
const block = RN_FIREBASE_DID_FINISH_LAUNCHING_IDENTIFIER + RN_FIREBASE_DID_FINISH_LAUNCHING_CODE
appDelegate = appDelegate.replace(RN_FIREBASE_DID_FINISH_LAUNCHING_IDENTIFIER, block)
} else {
throw new Error('Failed to detect didFinishLaunchingWithOptions in AppDelegate.m')
}
return appDelegate
}
const withRnFirebaseIosAppDelegate: ConfigPlugin = (config) => {
return withAppDelegate(config, (config) => {
if (config.modResults.language === 'objc') {
config.modResults.contents = modifyAppDelegate(config.modResults.contents)
} else {
WarningAggregator.addWarningIOS('withRnFirebaseIosAppDelegate', 'Swift AppDelegate files are not supported yet.')
}
return config
})
}
type Props = {
GoogleServicesInfoPlist: string
}
async function saveFileAsync(path: string, content: string): Promise<void> {
return fs.promises.writeFile(path, content, 'utf8')
}
async function addGoogleServiceInfoPlist(config: ExportedConfigWithProps, { GoogleServicesInfoPlist }: Props) {
try {
if (!config.modRequest.projectName) {
throw new Error('missing iOS project name.')
}
const path = resolve(
config.modRequest.platformProjectRoot,
config.modRequest.projectName || '',
'GoogleService-Info.plist'
)
if (!GoogleServicesInfoPlist) {
throw new Error('Missing GoogleService-Info.plist file.')
}
saveFileAsync(path, GoogleServicesInfoPlist)
} catch (e) {
WarningAggregator.addWarningIOS('with-rn-firebase-ios', `Couldn't add GoogleService-Info.plist - ${e}.`)
}
}
const withGoogleServiceInfoPlist: ConfigPlugin<Props> = (config, props) => {
return withDangerousMod(config, [
'ios',
async (config) => {
await addGoogleServiceInfoPlist(config, props)
return config
}
])
}
export const withRnFirebaseIos: ConfigPlugin<Props> = (config, props) => {
config = withGoogleServiceInfoPlist(config, props)
config = withRnFirebaseIosAppDelegate(config)
return config
}
const { GoogleServicesInfoPlist } = require('./GoogleService-Info')
export default withRnFirebaseIos(config, {
GoogleServicesInfoPlist
}) For developer, the final API will look like this: const config = {
// user's expo config
}
const { GoogleServicesInfoPlist } = require('./GoogleService-Info')
export default withRnFirebase(config, {
GoogleServicesInfoPlist
}) And it'll work for any RN project, Expo or otherwise. |
Beta Was this translation helpful? Give feedback.
-
Hi, I've created and published a Edit: The PR: #5480 |
Beta Was this translation helpful? Give feedback.
-
@barthap's plugin has been working with RNFB |
Beta Was this translation helpful? Give feedback.
-
Some updates:
|
Beta Was this translation helpful? Give feedback.
Some updates:
yarn install
calls (without any native modifications) thanks to Config Plugins