diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h index 65c8662763..9f232ea941 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h @@ -23,6 +23,26 @@ FLUTTER_EXPORT - (instancetype)initFromDefaultSourceForConfiguration; +/** + Returns the file name for the given asset. + The returned file name can be used to access the asset in the application's main bundle. + + - Parameter asset: The name of the asset. The name can be hierarchical. + - Returns: the file name to be used for lookup in the main bundle. + */ ++ (NSString*)lookupKeyForAsset:(NSString*)asset; + +/** + Returns the file name for the given asset which originates from the specified package. + The returned file name can be used to access the asset in the application's main bundle. + + - Parameters: + - asset: The name of the asset. The name can be hierarchical. + - package: The name of the package from which the asset originates. + - Returns: the file name to be used for lookup in the main bundle. + */ ++ (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package; + @end #endif // FLUTTER_FLUTTERDARTPROJECT_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h index 396d8d95c8..b6c964c6b3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h @@ -183,6 +183,26 @@ NS_ASSUME_NONNULL_BEGIN - Parameters delegate: The receiving object, such as the plugin's main class. */ - (void)addApplicationDelegate:(NSObject*)delegate; + +/** + Returns the file name for the given asset. + The returned file name can be used to access the asset in the application's main bundle. + + - Parameter asset: The name of the asset. The name can be hierarchical. + - Returns: the file name to be used for lookup in the main bundle. + */ +- (NSString*)lookupKeyForAsset:(NSString*)asset; + +/** + Returns the file name for the given asset which originates from the specified package. + The returned file name can be used to access the asset in the application's main bundle. + + - Parameters: + - asset: The name of the asset. The name can be hierarchical. + - package: The name of the package from which the asset originates. + - Returns: the file name to be used for lookup in the main bundle. + */ +- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package; @end /** diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h index 68e0d0f65a..7ef6868a27 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h @@ -22,6 +22,26 @@ FLUTTER_EXPORT - (void)handleStatusBarTouches:(UIEvent*)event; +/** + Returns the file name for the given asset. + The returned file name can be used to access the asset in the application's main bundle. + + - Parameter asset: The name of the asset. The name can be hierarchical. + - Returns: the file name to be used for lookup in the main bundle. + */ +- (NSString*)lookupKeyForAsset:(NSString*)asset; + +/** + Returns the file name for the given asset which originates from the specified package. + The returned file name can be used to access the asset in the application's main bundle. + + - Parameters: + - asset: The name of the asset. The name can be hierarchical. + - package: The name of the package from which the asset originates. + - Returns: the file name to be used for lookup in the main bundle. + */ +- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package; + /** Sets the first route that the Flutter app shows. The default is "/". diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm index 5f7f440be4..7198b9082a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm @@ -284,4 +284,13 @@ - (void)addApplicationDelegate:(NSObject*)delegate { [_appDelegate.pluginDelegates addObject:delegate]; } + +- (NSString*)lookupKeyForAsset:(NSString*)asset { + return [FlutterDartProject lookupKeyForAsset:asset]; +} + +- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package { + return [FlutterDartProject lookupKeyForAsset:asset fromPackage:package]; +} + @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 468cef1667..d5f30d0266 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -146,16 +146,29 @@ static NSURL* URLForSwitch(const fxl::StringView name) { #pragma mark - Assets-related utilities -+ (NSString*)pathForFlutterAssetsFromBundle:(NSBundle*)bundle { ++ (NSString*)flutterAssetsName:(NSBundle*)bundle { NSString* flutterAssetsName = [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"]; if (flutterAssetsName == nil) { // Default to "flutter_assets" flutterAssetsName = @"flutter_assets"; } + return flutterAssetsName; +} ++ (NSString*)pathForFlutterAssetsFromBundle:(NSBundle*)bundle { + NSString* flutterAssetsName = [FlutterDartProject flutterAssetsName:bundle]; return [bundle pathForResource:flutterAssetsName ofType:nil]; } ++ (NSString*)lookupKeyForAsset:(NSString*)asset { + NSString* flutterAssetsName = [FlutterDartProject flutterAssetsName: [NSBundle mainBundle]]; + return [NSString stringWithFormat:@"%@/%@", flutterAssetsName, asset]; +} + ++ (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package { + return [self lookupKeyForAsset:[NSString stringWithFormat:@"packages/%@/%@", package, asset]]; +} + #pragma mark - Launching the project in a preconfigured engine. static NSString* NSStringFromVMType(VMType type) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 87682de7b3..a467a5a8cf 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -908,4 +908,13 @@ constexpr CGFloat kStandardStatusBarHeight = 20.0; - (void)textureFrameAvailable:(int64_t)textureId { _platformView->MarkTextureFrameAvailable(textureId); } + +- (NSString*)lookupKeyForAsset:(NSString*)asset { + return [FlutterDartProject lookupKeyForAsset:asset]; +} + +- (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package { + return [FlutterDartProject lookupKeyForAsset:asset fromPackage:package]; +} + @end