From 1d90b1bdcf5022c6d671d3eedb3b753480293b25 Mon Sep 17 00:00:00 2001 From: Max Ast Date: Thu, 28 Mar 2024 15:39:45 +0100 Subject: [PATCH 1/4] add vscode settings to use eslint as formatter --- .vscode/settings.json | 9 +++++++++ plugin/src/withExpoConfig.ts | 6 +++--- plugin/src/withPodfile.ts | 2 +- plugin/src/withShareExtensionEntitlements.ts | 2 +- plugin/src/withShareExtensionTarget.ts | 2 +- plugin/src/xcode/addBuildPhases.ts | 16 ++++++++-------- plugin/src/xcode/addPbxGroup.ts | 6 +++--- plugin/src/xcode/addProductFile.ts | 2 +- plugin/src/xcode/addTargetDependency.ts | 2 +- plugin/src/xcode/addToPbxNativeTargetSection.ts | 2 +- plugin/src/xcode/addToPbxProjectSection.ts | 2 +- plugin/src/xcode/addToXCConfigurationList.ts | 4 ++-- 12 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a81aa9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "editor.defaultFormatter": "dbaeumer.vscode-eslint", + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "always" + }, + "eslint.format.enable": true, + "lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB", + "lldb.launch.expressions": "native" +} diff --git a/plugin/src/withExpoConfig.ts b/plugin/src/withExpoConfig.ts index f655130..54a470b 100644 --- a/plugin/src/withExpoConfig.ts +++ b/plugin/src/withExpoConfig.ts @@ -25,7 +25,7 @@ export const withExpoConfig: ConfigPlugin = (config) => { config.extra?.eas?.build?.experimental?.ios?.appExtensions; const shareExtensionConfig = iosExtensions?.find( - (extension) => extension.targetName === extensionName + (extension) => extension.targetName === extensionName, ); return { @@ -49,7 +49,7 @@ export const withExpoConfig: ConfigPlugin = (config) => { entitlements: { ...shareExtensionConfig?.entitlements, "com.apple.security.application-groups": getAppGroups( - config.ios?.bundleIdentifier + config.ios?.bundleIdentifier, ), ...(config.ios.usesAppleSignIn && { "com.apple.developer.applesignin": ["Default"], @@ -57,7 +57,7 @@ export const withExpoConfig: ConfigPlugin = (config) => { }, }, ...(iosExtensions?.filter( - (extension) => extension.targetName !== extensionName + (extension) => extension.targetName !== extensionName, ) ?? []), ], }, diff --git a/plugin/src/withPodfile.ts b/plugin/src/withPodfile.ts index f525580..4ae780f 100644 --- a/plugin/src/withPodfile.ts +++ b/plugin/src/withPodfile.ts @@ -14,7 +14,7 @@ export const withPodfile: ConfigPlugin<{ (config) => { const podFilePath = path.join( config.modRequest.platformProjectRoot, - "Podfile" + "Podfile", ); let podfileContent = fs.readFileSync(podFilePath).toString(); diff --git a/plugin/src/withShareExtensionEntitlements.ts b/plugin/src/withShareExtensionEntitlements.ts index 5733019..2c9d547 100644 --- a/plugin/src/withShareExtensionEntitlements.ts +++ b/plugin/src/withShareExtensionEntitlements.ts @@ -15,7 +15,7 @@ export const withShareExtensionEntitlements: ConfigPlugin = (config) => { const targetPath = path.join( config.modRequest.platformProjectRoot, - targetName + targetName, ); const filePath = path.join(targetPath, `${targetName}.entitlements`); diff --git a/plugin/src/withShareExtensionTarget.ts b/plugin/src/withShareExtensionTarget.ts index 6f4ab61..ca42e70 100644 --- a/plugin/src/withShareExtensionTarget.ts +++ b/plugin/src/withShareExtensionTarget.ts @@ -32,7 +32,7 @@ export const withShareExtensionTarget: ConfigPlugin<{ if (config.ios?.googleServicesFile && !googleServicesFile) { console.warn( - "Warning: No Google Services file specified for Share Extension" + "Warning: No Google Services file specified for Share Extension", ); } diff --git a/plugin/src/xcode/addBuildPhases.ts b/plugin/src/xcode/addBuildPhases.ts index fa484c0..a2060b6 100644 --- a/plugin/src/xcode/addBuildPhases.ts +++ b/plugin/src/xcode/addBuildPhases.ts @@ -17,7 +17,7 @@ export function addBuildPhases( group: string; }; resources: string[]; - } + }, ) { const buildPath = `"$(CONTENTS_FOLDER_PATH)/ShareExtensions"`; const targetType = "app_extension"; @@ -33,7 +33,7 @@ export function addBuildPhases( shellScript: 'export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"\necho "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"\nif [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then\n echo "Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"\n exit 2\n fi\n else\n open "$SRCROOT/../node_modules/react-native/scripts/launchPackager.command" || echo "Can\'t start packager automatically"\n fi\nfi\n', }, - buildPath + buildPath, ); // Sources build phase @@ -43,7 +43,7 @@ export function addBuildPhases( groupName, targetUuid, targetType, - buildPath + buildPath, ); // Copy files build phase @@ -52,7 +52,7 @@ export function addBuildPhases( "PBXCopyFilesBuildPhase", groupName, xcodeProject.getFirstTarget().uuid, - targetType + targetType, ); xcodeProject.addBuildPhase( @@ -60,7 +60,7 @@ export function addBuildPhases( "PBXCopyFilesBuildPhase", "Copy Files", xcodeProject.getFirstTarget().uuid, - targetType + targetType, ); xcodeProject.addToPbxCopyfilesBuildPhase(productFile); @@ -71,7 +71,7 @@ export function addBuildPhases( groupName, targetUuid, targetType, - buildPath + buildPath, ); // Resources build phase @@ -81,7 +81,7 @@ export function addBuildPhases( groupName, targetUuid, targetType, - buildPath + buildPath, ); // Add shell script build phase @@ -95,6 +95,6 @@ export function addBuildPhases( shellScript: 'set -e; NODE_BINARY=${NODE_BINARY:-node}; REACT_NATIVE_SCRIPTS_PATH=$("$NODE_BINARY" --print "require(\'path\').dirname(require.resolve(\'react-native/package.json\')) + \'/scripts\'"); WITH_ENVIRONMENT="$REACT_NATIVE_SCRIPTS_PATH/xcode/with-environment.sh"; REACT_NATIVE_XCODE="$REACT_NATIVE_SCRIPTS_PATH/react-native-xcode.sh"; export ENTRY_FILE=index.share.js; /bin/sh -c "$WITH_ENVIRONMENT $REACT_NATIVE_XCODE";', }, - buildPath + buildPath, ); } diff --git a/plugin/src/xcode/addPbxGroup.ts b/plugin/src/xcode/addPbxGroup.ts index de611b7..1c5940c 100644 --- a/plugin/src/xcode/addPbxGroup.ts +++ b/plugin/src/xcode/addPbxGroup.ts @@ -16,7 +16,7 @@ export function addPbxGroup( fonts: string[]; googleServicesFilePath?: string; preprocessingFilePath?: string; - } + }, ) { const targetPath = path.join(platformProjectRoot, targetName); @@ -27,7 +27,7 @@ export function addPbxGroup( copyFileSync( path.join(__dirname, "../../swift/ShareExtensionViewController.swift"), targetPath, - "ShareExtensionViewController.swift" + "ShareExtensionViewController.swift", ); for (const font of fonts) { @@ -55,7 +55,7 @@ export function addPbxGroup( const { uuid: pbxGroupUuid } = xcodeProject.addPbxGroup( files, targetName, - targetName + targetName, ); // Add PBXGroup to top level group diff --git a/plugin/src/xcode/addProductFile.ts b/plugin/src/xcode/addProductFile.ts index 480615c..26b1109 100644 --- a/plugin/src/xcode/addProductFile.ts +++ b/plugin/src/xcode/addProductFile.ts @@ -2,7 +2,7 @@ import { XcodeProject } from "expo/config-plugins"; export function addProductFile( xcodeProject: XcodeProject, - { targetName }: { targetName: string; groupName: string } + { targetName }: { targetName: string; groupName: string }, ) { const productFile = xcodeProject.addProductFile(targetName, { group: "Copy Files", diff --git a/plugin/src/xcode/addTargetDependency.ts b/plugin/src/xcode/addTargetDependency.ts index 41460be..a7576d2 100644 --- a/plugin/src/xcode/addTargetDependency.ts +++ b/plugin/src/xcode/addTargetDependency.ts @@ -2,7 +2,7 @@ import { XcodeProject } from "expo/config-plugins"; export function addTargetDependency( xcodeProject: XcodeProject, - target: { uuid: string } + target: { uuid: string }, ) { if (!xcodeProject.hash.project.objects["PBXTargetDependency"]) { xcodeProject.hash.project.objects["PBXTargetDependency"] = {}; diff --git a/plugin/src/xcode/addToPbxNativeTargetSection.ts b/plugin/src/xcode/addToPbxNativeTargetSection.ts index b6ab9c1..3fabdb0 100644 --- a/plugin/src/xcode/addToPbxNativeTargetSection.ts +++ b/plugin/src/xcode/addToPbxNativeTargetSection.ts @@ -12,7 +12,7 @@ export function addToPbxNativeTargetSection( targetUuid: string; productFile: { fileRef: string }; xCConfigurationList: { uuid: string }; - } + }, ) { const target = { uuid: targetUuid, diff --git a/plugin/src/xcode/addToPbxProjectSection.ts b/plugin/src/xcode/addToPbxProjectSection.ts index af8c529..138e4fc 100644 --- a/plugin/src/xcode/addToPbxProjectSection.ts +++ b/plugin/src/xcode/addToPbxProjectSection.ts @@ -2,7 +2,7 @@ import { XcodeProject } from "expo/config-plugins"; export function addToPbxProjectSection( xcodeProject: XcodeProject, - target: { uuid: string } + target: { uuid: string }, ) { xcodeProject.addToPbxProjectSection(target); diff --git a/plugin/src/xcode/addToXCConfigurationList.ts b/plugin/src/xcode/addToXCConfigurationList.ts index d0e164a..8687a81 100644 --- a/plugin/src/xcode/addToXCConfigurationList.ts +++ b/plugin/src/xcode/addToXCConfigurationList.ts @@ -12,7 +12,7 @@ export function addXCConfigurationList( currentProjectVersion: string; bundleIdentifier: string; marketingVersion?: string; - } + }, ) { const commonBuildSettings = { CLANG_ENABLE_MODULES: "YES", @@ -51,7 +51,7 @@ export function addXCConfigurationList( const xCConfigurationList = xcodeProject.addXCConfigurationList( buildConfigurationsList, "Release", - `Build configuration list for PBXNativeTarget "${targetName}"` + `Build configuration list for PBXNativeTarget "${targetName}"`, ); return xCConfigurationList; From 49dacba086430319c50a5d6f3e19f169b15e8786 Mon Sep 17 00:00:00 2001 From: Max Ast Date: Thu, 28 Mar 2024 15:41:13 +0100 Subject: [PATCH 2/4] add google reverse client ID to CFBundleURLSchemes --- plugin/src/index.ts | 3 +- plugin/src/withShareExtensionInfoPlist.ts | 48 +++++++++++++++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/plugin/src/index.ts b/plugin/src/index.ts index 2562521..07ae40a 100644 --- a/plugin/src/index.ts +++ b/plugin/src/index.ts @@ -56,7 +56,7 @@ const withShareExtension: ConfigPlugin<{ } const expoFontPlugin = config.plugins?.find( - (p) => Array.isArray(p) && p.length && p.at(0) === "expo-font" + (p) => Array.isArray(p) && p.length && p.at(0) === "expo-font", ); const fonts = expoFontPlugin?.at(1).fonts ?? []; @@ -72,6 +72,7 @@ const withShareExtension: ConfigPlugin<{ backgroundColor: props?.backgroundColor, height: props?.height, preprocessingFile: props.preprocessingFile, + googleServicesFile: props?.googleServicesFile, }, ], withShareExtensionEntitlements, diff --git a/plugin/src/withShareExtensionInfoPlist.ts b/plugin/src/withShareExtensionInfoPlist.ts index 3e7d144..d5de1b9 100644 --- a/plugin/src/withShareExtensionInfoPlist.ts +++ b/plugin/src/withShareExtensionInfoPlist.ts @@ -9,18 +9,53 @@ import { getShareExtensionName, } from "./index"; +const getReversedClientId = (googleServiceFile: string): string => { + try { + const googleServicePlist = fs.readFileSync(googleServiceFile, "utf8"); + + const googleServiceJson = plist.parse(googleServicePlist); + const REVERSED_CLIENT_ID = googleServiceJson.REVERSED_CLIENT_ID; + + if (!REVERSED_CLIENT_ID) { + throw new TypeError("REVERSED_CLIENT_ID missing"); + } + + return REVERSED_CLIENT_ID; + } catch { + throw new Error( + "[expo-share-extension] Failed to parse your share extension's GoogleService-Info.plist. Are you sure it is a valid Info.Plist file with a REVERSE_CLIENT_ID field?", + ); + } +}; + export const withShareExtensionInfoPlist: ConfigPlugin<{ fonts: string[]; backgroundColor?: BackgroundColor; height?: Height; preprocessingFile?: string; -}> = (config, { fonts = [], backgroundColor, height, preprocessingFile }) => { + googleServicesFile?: string; +}> = ( + config, + { + fonts = [], + backgroundColor, + height, + preprocessingFile, + googleServicesFile, + }, +) => { return withInfoPlist(config, (config) => { const targetName = getShareExtensionName(config); + let reversedClientId: string | undefined; + + if (googleServicesFile) { + reversedClientId = getReversedClientId(googleServicesFile); + } + const targetPath = path.join( config.modRequest.platformProjectRoot, - targetName + targetName, ); const filePath = path.join(targetPath, "Info.plist"); @@ -35,6 +70,13 @@ export const withShareExtensionInfoPlist: ConfigPlugin<{ CFBundlePackageType: "$(PRODUCT_BUNDLE_PACKAGE_TYPE)", CFBundleShortVersionString: "$(MARKETING_VERSION)", CFBundleVersion: "$(CURRENT_PROJECT_VERSION)", + ...(reversedClientId && { + CFBundleURLTypes: [ + { + CFBundleURLSchemes: [reversedClientId], + }, + ], + }), LSRequiresIPhoneOS: true, NSAppTransportSecurity: { NSExceptionDomains: { @@ -68,7 +110,7 @@ export const withShareExtensionInfoPlist: ConfigPlugin<{ ...(preprocessingFile && { NSExtensionJavaScriptPreprocessingFile: path.basename( preprocessingFile, - path.extname(preprocessingFile) + path.extname(preprocessingFile), ), }), }, From 129f580d4af88f5082148b7a72468b32a8f9bc1b Mon Sep 17 00:00:00 2001 From: Max Ast Date: Thu, 28 Mar 2024 17:10:29 +0100 Subject: [PATCH 3/4] add google sign in to with-firebase --- examples/with-firebase/App.tsx | 8 +- examples/with-firebase/ShareExtension.tsx | 61 +-- examples/with-firebase/app.json | 1 + .../components/AppleAuthLogin.tsx | 39 -- examples/with-firebase/components/Login.tsx | 37 ++ examples/with-firebase/ios/Podfile.lock | 38 +- .../withfirebase.xcodeproj/project.pbxproj | 422 +++++++++--------- .../with-firebase/ios/withfirebase/Info.plist | 2 +- .../ios/withfirebaseShareExtension/Info.plist | 9 + examples/with-firebase/lib/auth.ts | 66 +++ examples/with-firebase/package-lock.json | 16 + examples/with-firebase/package.json | 7 +- 12 files changed, 422 insertions(+), 284 deletions(-) delete mode 100644 examples/with-firebase/components/AppleAuthLogin.tsx create mode 100644 examples/with-firebase/components/Login.tsx create mode 100644 examples/with-firebase/lib/auth.ts diff --git a/examples/with-firebase/App.tsx b/examples/with-firebase/App.tsx index 4b8f7bf..9a8e72d 100644 --- a/examples/with-firebase/App.tsx +++ b/examples/with-firebase/App.tsx @@ -2,7 +2,7 @@ import auth, { type FirebaseAuthTypes } from "@react-native-firebase/auth"; import { useEffect, useState } from "react"; import { Alert, Button, StyleSheet, Text, View } from "react-native"; -import { AppleAuthLoginButton } from "./components/AppleAuthLogin"; +import { Login } from "./components/Login"; export default function App() { const [session, setSession] = useState(null); @@ -37,7 +37,7 @@ export default function App() { - Basic Example + Firebase Auth Example - Alert.alert("Authentication Error", error.message) + Alert.alert("Authentication Error", error.message), ) } /> ) : ( - + )} diff --git a/examples/with-firebase/ShareExtension.tsx b/examples/with-firebase/ShareExtension.tsx index 4eece33..ee854b9 100644 --- a/examples/with-firebase/ShareExtension.tsx +++ b/examples/with-firebase/ShareExtension.tsx @@ -3,7 +3,7 @@ import { type InitialProps, close } from "expo-share-extension"; import { useEffect, useState } from "react"; import { Alert, Button, Text, View, StyleSheet } from "react-native"; -import { AppleAuthLoginButton } from "./components/AppleAuthLogin"; +import { Login } from "./components/Login"; export default function ShareExtension({ url, text }: InitialProps) { const [session, setSession] = useState(null); @@ -35,35 +35,42 @@ export default function ShareExtension({ url, text }: InitialProps) { return ( - - Firebase Example - - {url && ( + - URL: {url} + Firebase Example - )} - {text && ( - - Text: {text} - - )} -