|
|
@@ -0,0 +1,77 @@ |
|
|
const { withAppDelegate } = require("expo/config-plugins"); |
|
|
const { |
|
|
mergeContents, |
|
|
} = require("@expo/config-plugins/build/utils/generateCode"); |
|
|
|
|
|
const withExpoP3 = (config) => { |
|
|
return withAppDelegate(config, (config) => { |
|
|
if ( |
|
|
config.modResults.language === "objc" || |
|
|
config.modResults.language === "objcpp" |
|
|
) { |
|
|
config.modResults.contents = modifyObjCAppDelegate( |
|
|
config.modResults.contents, |
|
|
); |
|
|
} else if (config.modResults.language === "swift") { |
|
|
config.modResults.contents = modifySwiftAppDelegate( |
|
|
config.modResults.contents, |
|
|
); |
|
|
} else { |
|
|
console.warn( |
|
|
`Unable to modify AppDelegate: Unsupported language ${config.modResults.language}`, |
|
|
); |
|
|
} |
|
|
return config; |
|
|
}); |
|
|
}; |
|
|
|
|
|
function modifyObjCAppDelegate(appDelegateContent) { |
|
|
// Add import statement |
|
|
appDelegateContent = mergeContents({ |
|
|
src: appDelegateContent, |
|
|
newSrc: "#import <React/RCTConvert.h>", |
|
|
anchor: /#import "AppDelegate\.h"/, |
|
|
offset: 1, |
|
|
tag: "expo-p3-import", |
|
|
comment: "//", |
|
|
}).contents; |
|
|
|
|
|
// Add RCTSetDefaultColorSpace call |
|
|
appDelegateContent = mergeContents({ |
|
|
src: appDelegateContent, |
|
|
newSrc: " RCTSetDefaultColorSpace(RCTColorSpaceDisplayP3);", |
|
|
anchor: |
|
|
/return \[super application:application didFinishLaunchingWithOptions:launchOptions\];/, |
|
|
offset: 0, |
|
|
tag: "expo-p3-setup", |
|
|
comment: "//", |
|
|
}).contents; |
|
|
|
|
|
return appDelegateContent; |
|
|
} |
|
|
|
|
|
function modifySwiftAppDelegate(appDelegateContent) { |
|
|
// Add import statement |
|
|
appDelegateContent = mergeContents({ |
|
|
src: appDelegateContent, |
|
|
newSrc: "import React", |
|
|
anchor: /import UIKit/, |
|
|
offset: 1, |
|
|
tag: "expo-p3-import", |
|
|
comment: "//", |
|
|
}).contents; |
|
|
|
|
|
// Add RCTSetDefaultColorSpace call |
|
|
appDelegateContent = mergeContents({ |
|
|
src: appDelegateContent, |
|
|
newSrc: " RCTSetDefaultColorSpace(RCTColorSpaceDisplayP3)", |
|
|
anchor: /super\.application\(.*\)/, |
|
|
offset: 0, |
|
|
tag: "expo-p3-setup", |
|
|
comment: "//", |
|
|
}).contents; |
|
|
|
|
|
return appDelegateContent; |
|
|
} |
|
|
|
|
|
module.exports = withExpoP3; |