Skip to content

Commit 0e22ea7

Browse files
authored
[ios_platform_images] Add ios platform images (flutter#2391)
* Added ios_platform_images. * Removed bin files and moved to io.flutter package. * added myself as the codeowner * added docstring for example * ran formatter on ios_platform_images.dart * Ran formatter. * took CI format suggestions * added homepage * added another homepage * updated package and plugin name fields * added flutter version limit * fixed widget test * Removed platform message handler. * Added references to apple documentation. * added docstring * Moved plugin to java. * updated description
1 parent 6bf0290 commit 0e22ea7

File tree

91 files changed

+2092
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+2092
-0
lines changed

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ packages/google_maps_flutter/* @iskakaushik
1313
packages/google_sign_in/* @cyanglaz @mehmetf
1414
packages/image_picker/* @cyanglaz
1515
packages/in_app_purchase/* @mklim @cyanglaz
16+
packages/ios_platform_images/* @gaaclarke
1617
packages/instrumentation_adapter/* @collinjackson @digiter
1718
packages/package_info/* @cyanglaz
1819
packages/path_provider/* @collinjackson
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.dart_tool/
3+
4+
.packages
5+
.pub/
6+
7+
build/
8+
pubspec.lock
9+
.idea/
10+
.metadata
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## 0.0.1
2+
3+
Initial release. Includes functionality to share images iOS images with Flutter
4+
and Flutter assets with iOS.

packages/ios_platform_images/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2017 The Chromium Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following disclaimer
11+
in the documentation and/or other materials provided with the
12+
distribution.
13+
* Neither the name of Google Inc. nor the names of its
14+
contributors may be used to endorse or promote products derived from
15+
this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# IOS Platform Images
2+
3+
A Flutter plugin to share images between Flutter and iOS.
4+
5+
This allows Flutter to load images from Images.xcassets and iOS code to load
6+
Flutter images.
7+
8+
When loading images from Image.xcassets the device specific variant is chosen
9+
([iOS documentation](https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/image-size-and-resolution/)).
10+
11+
## Usage
12+
13+
### iOS->Flutter Example
14+
15+
``` dart
16+
// Import package
17+
import 'package:ios_platform_images/ios_platform_images.dart';
18+
19+
Widget build(BuildContext context) {
20+
return MaterialApp(
21+
home: Scaffold(
22+
body: Center(
23+
child: Image(image: IosPlatformImages.load("flutter")),
24+
),
25+
//..
26+
),
27+
);
28+
}
29+
```
30+
31+
`IosPlatformImages.load` functions like [[UIImage imageNamed:]](https://developer.apple.com/documentation/uikit/uiimage/1624146-imagenamed).
32+
33+
### Flutter->iOS Example
34+
35+
```objc
36+
#import <ios_platform_images/UIImage+ios_platform_images.h>
37+
38+
static UIImageView* MakeImage() {
39+
UIImage* image = [UIImage flutterImageWithName:@"assets/foo.png"];
40+
return [[UIImageView alloc] initWithImage:image];
41+
}
42+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
group 'io.flutter.ios_platform_images'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
google()
7+
jcenter()
8+
}
9+
10+
dependencies {
11+
classpath 'com.android.tools.build:gradle:3.4.2'
12+
}
13+
}
14+
15+
rootProject.allprojects {
16+
repositories {
17+
google()
18+
jcenter()
19+
}
20+
}
21+
22+
apply plugin: 'com.android.library'
23+
24+
android {
25+
compileSdkVersion 28
26+
27+
defaultConfig {
28+
minSdkVersion 16
29+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
30+
}
31+
lintOptions {
32+
disable 'InvalidPackage'
33+
}
34+
testOptions {
35+
unitTests.includeAndroidResources = true
36+
}
37+
}
38+
39+
dependencies {
40+
compileOnly 'androidx.annotation:annotation:1.0.0'
41+
testImplementation 'junit:junit:4.12'
42+
testImplementation 'org.mockito:mockito-core:1.10.19'
43+
testImplementation 'androidx.test:core:1.0.0'
44+
testImplementation 'org.robolectric:robolectric:4.3'
45+
}
46+
47+
// TODO(mklim): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
48+
afterEvaluate {
49+
def containsEmbeddingDependencies = false
50+
for (def configuration : configurations.all) {
51+
for (def dependency : configuration.dependencies) {
52+
if (dependency.group == 'io.flutter' &&
53+
dependency.name.startsWith('flutter_embedding') &&
54+
dependency.isTransitive())
55+
{
56+
containsEmbeddingDependencies = true
57+
break
58+
}
59+
}
60+
}
61+
if (!containsEmbeddingDependencies) {
62+
android {
63+
dependencies {
64+
def lifecycle_version = "1.1.1"
65+
compileOnly "android.arch.lifecycle:runtime:$lifecycle_version"
66+
compileOnly "android.arch.lifecycle:common:$lifecycle_version"
67+
compileOnly "android.arch.lifecycle:common-java8:$lifecycle_version"
68+
}
69+
}
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.gradle.jvmargs=-Xmx1536M
2+
android.enableR8=true
3+
android.useAndroidX=true
4+
android.enableJetifier=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'ios_platform_images'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.ios_platform_images">
3+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.flutter.ios_platform_images;
2+
3+
import io.flutter.plugin.common.MethodCall;
4+
import io.flutter.plugin.common.MethodChannel;
5+
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
6+
import io.flutter.plugin.common.MethodChannel.Result;
7+
import io.flutter.plugin.common.PluginRegistry.Registrar;
8+
9+
public class IosPlatformImagesPlugin implements MethodCallHandler {
10+
public static void registerWith(Registrar registrar) {
11+
MethodChannel channel =
12+
new MethodChannel(registrar.messenger(), "plugins.flutter.io/ios_platform_images");
13+
final IosPlatformImagesPlugin instance = new IosPlatformImagesPlugin();
14+
channel.setMethodCallHandler(instance);
15+
}
16+
17+
@Override
18+
public void onMethodCall(MethodCall call, Result result) {
19+
result.error("AndroidNotSupported", "This plugin is for iOS only.", null);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
/build/
32+
33+
# Web related
34+
lib/generated_plugin_registrant.dart
35+
36+
# Exceptions to above rules.
37+
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ios_platform_images_example
2+
3+
Demonstrates how to use the ios_platform_images plugin.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter application.
8+
9+
A few resources to get you started if this is your first Flutter project:
10+
11+
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12+
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13+
14+
For help getting started with Flutter, view our
15+
[online documentation](https://flutter.dev/docs), which offers tutorials,
16+
samples, guidance on mobile development, and a full API reference.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
compileSdkVersion 28
30+
31+
sourceSets {
32+
main.java.srcDirs += 'src/main/kotlin'
33+
}
34+
35+
lintOptions {
36+
disable 'InvalidPackage'
37+
}
38+
39+
defaultConfig {
40+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41+
applicationId "com.example.ios_platform_images_example"
42+
minSdkVersion 16
43+
targetSdkVersion 28
44+
versionCode flutterVersionCode.toInteger()
45+
versionName flutterVersionName
46+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
47+
}
48+
49+
buildTypes {
50+
release {
51+
// TODO: Add your own signing config for the release build.
52+
// Signing with the debug keys for now, so `flutter run --release` works.
53+
signingConfig signingConfigs.debug
54+
}
55+
}
56+
}
57+
58+
flutter {
59+
source '../..'
60+
}
61+
62+
dependencies {
63+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64+
testImplementation 'junit:junit:4.12'
65+
androidTestImplementation 'androidx.test:runner:1.1.1'
66+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.ios_platform_images_example">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.ios_platform_images_example">
3+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
4+
calls FlutterMain.startInitialization(this); in its onCreate method.
5+
In most cases you can leave this as-is, but you if you want to provide
6+
additional functionality it is fine to subclass or reimplement
7+
FlutterApplication and put your custom class here. -->
8+
<application
9+
android:name="io.flutter.app.FlutterApplication"
10+
android:label="ios_platform_images_example"
11+
android:icon="@mipmap/ic_launcher">
12+
<activity
13+
android:name=".MainActivity"
14+
android:launchMode="singleTop"
15+
android:theme="@style/LaunchTheme"
16+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
17+
android:hardwareAccelerated="true"
18+
android:windowSoftInputMode="adjustResize">
19+
<!-- This keeps the window background of the activity showing
20+
until Flutter renders its first frame. It can be removed if
21+
there is no splash screen (such as the default splash screen
22+
defined in @style/LaunchTheme). -->
23+
<meta-data
24+
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
25+
android:value="true" />
26+
<intent-filter>
27+
<action android:name="android.intent.action.MAIN"/>
28+
<category android:name="android.intent.category.LAUNCHER"/>
29+
</intent-filter>
30+
</activity>
31+
</application>
32+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.ios_platform_images_example
2+
3+
import android.os.Bundle
4+
import io.flutter.app.FlutterActivity
5+
import io.flutter.plugins.GeneratedPluginRegistrant
6+
7+
class MainActivity: FlutterActivity() {
8+
override fun onCreate(savedInstanceState: Bundle?) {
9+
super.onCreate(savedInstanceState)
10+
GeneratedPluginRegistrant.registerWith(this)
11+
}
12+
}

0 commit comments

Comments
 (0)