Skip to content

Commit

Permalink
Provide asset lookup key on ios (flutter#4817)
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias authored Mar 21, 2018
1 parent ca57221 commit 2114a88
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
20 changes: 20 additions & 0 deletions shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
20 changes: 20 additions & 0 deletions shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ NS_ASSUME_NONNULL_BEGIN
- Parameters delegate: The receiving object, such as the plugin's main class.
*/
- (void)addApplicationDelegate:(NSObject<FlutterPlugin>*)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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,13 @@ - (void)addMethodCallDelegate:(NSObject<FlutterPlugin>*)delegate
- (void)addApplicationDelegate:(NSObject<FlutterPlugin>*)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
15 changes: 14 additions & 1 deletion shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,29 @@ - (void)checkReadiness {

#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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,4 +908,13 @@ - (void)unregisterTexture:(int64_t)textureId {
- (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

0 comments on commit 2114a88

Please sign in to comment.