Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
8c3eeb57
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8c3eeb57
编写于
10月 13, 2016
作者:
A
Adam Barth
提交者:
GitHub
10月 13, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement PlatformPlugin on iOS (#3125)
Also, expose a convenience class for processing JSON messages.
上级
8b911be0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
235 addition
and
0 deletion
+235
-0
shell/platform/darwin/ios/BUILD.gn
shell/platform/darwin/ios/BUILD.gn
+5
-0
shell/platform/darwin/ios/framework/Headers/FlutterJSONMessageListener.h
...darwin/ios/framework/Headers/FlutterJSONMessageListener.h
+17
-0
shell/platform/darwin/ios/framework/Source/FlutterJSONMessageListener.mm
...darwin/ios/framework/Source/FlutterJSONMessageListener.mm
+30
-0
shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h
...tform/darwin/ios/framework/Source/FlutterPlatformPlugin.h
+9
-0
shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
...form/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
+169
-0
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
...form/darwin/ios/framework/Source/FlutterViewController.mm
+5
-0
未找到文件。
shell/platform/darwin/ios/BUILD.gn
浏览文件 @
8c3eeb57
...
...
@@ -19,6 +19,7 @@ shared_library("flutter_framework_dylib") {
"framework/Headers/FlutterAppDelegate.h",
"framework/Headers/FlutterAsyncMessageListener.h",
"framework/Headers/FlutterDartProject.h",
"framework/Headers/FlutterJSONMessageListener.h",
"framework/Headers/FlutterMacros.h",
"framework/Headers/FlutterMessageListener.h",
"framework/Headers/FlutterViewController.h",
...
...
@@ -33,6 +34,9 @@ shared_library("flutter_framework_dylib") {
"framework/Source/FlutterDartProject_Internal.h",
"framework/Source/FlutterDartSource.h",
"framework/Source/FlutterDartSource.mm",
"framework/Source/FlutterJSONMessageListener.mm",
"framework/Source/FlutterPlatformPlugin.h",
"framework/Source/FlutterPlatformPlugin.mm",
"framework/Source/FlutterView.h",
"framework/Source/FlutterView.mm",
"framework/Source/FlutterViewController.mm",
...
...
@@ -129,6 +133,7 @@ copy("framework_headers") {
"framework/Headers/FlutterAppDelegate.h",
"framework/Headers/FlutterAsyncMessageListener.h",
"framework/Headers/FlutterDartProject.h",
"framework/Headers/FlutterJSONMessageListener.h",
"framework/Headers/FlutterMacros.h",
"framework/Headers/FlutterMessageListener.h",
"framework/Headers/FlutterViewController.h",
...
...
shell/platform/darwin/ios/framework/Headers/FlutterJSONMessageListener.h
0 → 100644
浏览文件 @
8c3eeb57
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FLUTTERJSONMESSAGELISTENER_H_
#define FLUTTER_FLUTTERJSONMESSAGELISTENER_H_
#include "FlutterMessageListener.h"
FLUTTER_EXPORT
@interface
FlutterJSONMessageListener
:
NSObject
<
FlutterMessageListener
>
-
(
NSDictionary
*
)
didReceiveJSON
:(
NSDictionary
*
)
message
;
@end
#endif // FLUTTER_FLUTTERJSONMESSAGELISTENER_H_
shell/platform/darwin/ios/framework/Source/FlutterJSONMessageListener.mm
0 → 100644
浏览文件 @
8c3eeb57
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterJSONMessageListener.h"
@implementation
FlutterJSONMessageListener
-
(
NSString
*
)
didReceiveString
:(
NSString
*
)
message
{
NSError
*
error
=
nil
;
NSData
*
data
=
[
message
dataUsingEncoding
:
NSUTF8StringEncoding
];
NSDictionary
*
jsonObject
=
[
NSJSONSerialization
JSONObjectWithData
:
data
options
:
0
error
:&
error
];
if
(
error
)
return
nil
;
NSDictionary
*
response
=
[
self
didReceiveJSON
:
jsonObject
];
if
(
!
response
)
return
nil
;
NSData
*
responseData
=
[
NSJSONSerialization
dataWithJSONObject
:
response
options
:
0
error
:
nil
];
return
[[[
NSString
alloc
]
initWithData
:
responseData
encoding
:
NSUTF8StringEncoding
]
autorelease
];
}
-
(
NSDictionary
*
)
didReceiveJSON
:(
NSDictionary
*
)
message
{
return
nil
;
}
-
(
NSString
*
)
messageName
{
return
nil
;
}
@end
shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h
0 → 100644
浏览文件 @
8c3eeb57
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterJSONMessageListener.h"
@interface
FlutterPlatformPlugin
:
FlutterJSONMessageListener
@end
shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm
0 → 100644
浏览文件 @
8c3eeb57
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
#include <AudioToolbox/AudioToolbox.h>
#include <Foundation/Foundation.h>
#include <UIKit/UIApplication.h>
#include <UIKit/UIKit.h>
static
NSDictionary
*
GetDirectoryOfType
(
NSSearchPathDirectory
dir
)
{
NSArray
*
paths
=
NSSearchPathForDirectoriesInDomains
(
dir
,
NSUserDomainMask
,
YES
);
if
(
paths
.
count
==
0
)
return
nil
;
return
@{
@"path"
:
paths
.
firstObject
};
}
namespace
flutter
{
namespace
platform
{
// TODO(abarth): Move these definitions from system_chrome_impl.cc to here.
extern
const
char
*
const
kOrientationUpdateNotificationName
;
extern
const
char
*
const
kOrientationUpdateNotificationKey
;
extern
const
char
*
const
kOverlayStyleUpdateNotificationName
;
extern
const
char
*
const
kOverlayStyleUpdateNotificationKey
;
}
// namespace platform
}
// namespace flutter
using
namespace
flutter
::
platform
;
@implementation
FlutterPlatformPlugin
-
(
NSString
*
)
messageName
{
return
@"flutter/platform"
;
}
-
(
NSDictionary
*
)
didReceiveJSON
:(
NSDictionary
*
)
message
{
NSString
*
method
=
message
[
@"method"
];
NSArray
*
args
=
message
[
@"args"
];
if
([
method
isEqualToString
:
@"SystemSound.play"
])
{
[
self
playSystemSound
:
args
.
firstObject
];
}
else
if
([
method
isEqualToString
:
@"HapticFeedback.vibrate"
])
{
[
self
vibrateHapticFeedback
];
}
else
if
([
method
isEqualToString
:
@"UrlLauncher.launch"
])
{
[
self
launchURL
:
args
.
firstObject
];
}
else
if
([
method
isEqualToString
:
@"SystemChrome.setPreferredOrientations"
])
{
[
self
setSystemChromePreferredOrientatations
:
args
.
firstObject
];
}
else
if
([
method
isEqualToString
:
@"SystemChrome.setApplicationSwitcherDescription"
])
{
[
self
setSystemChromeApplicationSwitcherDescription
:
args
.
firstObject
];
}
else
if
([
method
isEqualToString
:
@"SystemChrome.setEnabledSystemUIOverlays"
])
{
[
self
setSystemChromeEnabledSystemUIOverlays
:
args
.
firstObject
];
}
else
if
([
method
isEqualToString
:
@"SystemChrome.setSystemUIOverlayStyle"
])
{
[
self
setSystemChromeSystemUIOverlayStyle
:
args
.
firstObject
];
}
else
if
([
method
isEqualToString
:
@"PathProvider.getTemporaryDirectory"
])
{
return
[
self
getPathProviderTemporaryDirectory
];
}
else
if
([
method
isEqualToString
:
@"PathProvider.getApplicationDocumentsDirectory"
])
{
return
[
self
getPathProviderApplicationDocumentsDirectory
];
}
else
{
// TODO(abarth): We should signal an error here that gets reported back to
// Dart.
}
return
nil
;
}
-
(
void
)
playSystemSound
:(
NSString
*
)
soundType
{
if
([
soundType
isEqualToString
:
@"SystemSoundType.click"
])
{
// All feedback types are specific to Android and are treated as equal on
// iOS. The surface must (and does) adopt the UIInputViewAudioFeedback
// protocol
[[
UIDevice
currentDevice
]
playInputClick
];
}
}
-
(
void
)
vibrateHapticFeedback
{
AudioServicesPlayAlertSound
(
kSystemSoundID_Vibrate
);
}
-
(
NSDictionary
*
)
launchURL
:(
NSString
*
)
urlString
{
NSURL
*
url
=
[
NSURL
URLWithString
:
urlString
];
UIApplication
*
application
=
[
UIApplication
sharedApplication
];
bool
success
=
[
application
canOpenURL
:
url
]
&&
[
application
openURL
:
url
];
return
@{
@"succes"
:
@
(
success
)
};
}
-
(
void
)
setSystemChromePreferredOrientatations
:(
NSArray
*
)
orientations
{
UIInterfaceOrientationMask
mask
=
0
;
if
(
orientations
.
count
==
0
)
{
mask
|=
UIInterfaceOrientationMaskAll
;
}
else
{
for
(
NSString
*
orientation
in
orientations
)
{
if
([
orientation
isEqualToString
:
@"DeviceOrientation.portraitUp"
])
mask
|=
UIInterfaceOrientationMaskPortrait
;
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.portraitDown"
])
mask
|=
UIInterfaceOrientationMaskPortraitUpsideDown
;
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.landscapeLeft"
])
mask
|=
UIInterfaceOrientationMaskLandscapeLeft
;
else
if
([
orientation
isEqualToString
:
@"DeviceOrientation.landscapeRight"
])
mask
|=
UIInterfaceOrientationMaskLandscapeRight
;
}
}
if
(
!
mask
)
return
;
[[
NSNotificationCenter
defaultCenter
]
postNotificationName:
@
(
kOrientationUpdateNotificationName
)
object:
nil
userInfo:
@{
@
(
kOrientationUpdateNotificationKey
)
:
@
(
mask
)
}];
}
-
(
void
)
setSystemChromeApplicationSwitcherDescription
:(
NSDictionary
*
)
object
{
// No counterpart on iOS but is a benign operation. So no asserts.
}
-
(
void
)
setSystemChromeEnabledSystemUIOverlays
:(
NSArray
*
)
overlays
{
// Checks if the top status bar should be visible. This platform ignores all
// other overlays
// We opt out of view controller based status bar visibility since we want
// to be able to modify this on the fly. The key used is
// UIViewControllerBasedStatusBarAppearance
[
UIApplication
sharedApplication
].
statusBarHidden
=
!
[
overlays
containsObject
:
@"SystemUiOverlay.top"
];
}
-
(
void
)
setSystemChromeSystemUIOverlayStyle
:(
NSString
*
)
style
{
UIStatusBarStyle
statusBarStyle
;
if
([
style
isEqualToString
:
@"SystemUiOverlayStyle.light"
])
statusBarStyle
=
UIStatusBarStyleLightContent
;
else
if
([
style
isEqualToString
:
@"SystemUiOverlayStyle.dark"
])
statusBarStyle
=
UIStatusBarStyleDefault
;
else
return
;
NSNumber
*
infoValue
=
[[
NSBundle
mainBundle
]
objectForInfoDictionaryKey:
@"UIViewControllerBasedStatusBarAppearance"
];
Boolean
delegateToViewController
=
(
infoValue
==
nil
||
[
infoValue
boolValue
]);
if
(
delegateToViewController
)
{
// This notification is respected by the iOS embedder
[[
NSNotificationCenter
defaultCenter
]
postNotificationName:
@
(
kOverlayStyleUpdateNotificationName
)
object:
nil
userInfo:
@{
@
(
kOverlayStyleUpdateNotificationKey
)
:
@
(
statusBarStyle
)
}];
}
else
{
// Note: -[UIApplication setStatusBarStyle] is deprecated in iOS9
// in favor of delegating to the view controller
[[
UIApplication
sharedApplication
]
setStatusBarStyle
:
statusBarStyle
];
}
}
-
(
NSDictionary
*
)
getPathProviderTemporaryDirectory
{
return
GetDirectoryOfType
(
NSCachesDirectory
);
}
-
(
NSDictionary
*
)
getPathProviderApplicationDocumentsDirectory
{
return
GetDirectoryOfType
(
NSDocumentDirectory
);
}
@end
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
浏览文件 @
8c3eeb57
...
...
@@ -15,6 +15,7 @@
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/shell/platform/darwin/common/platform_mac.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h"
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
#include "lib/ftl/functional/make_copyable.h"
...
...
@@ -36,6 +37,7 @@ void FlutterInit(int argc, const char* argv[]) {
sky
::
ViewportMetricsPtr
_viewportMetrics
;
shell
::
TouchMapper
_touchMapper
;
std
::
unique_ptr
<
shell
::
PlatformViewIOS
>
_platformView
;
base
::
scoped_nsprotocol
<
FlutterPlatformPlugin
*>
_platformPlugin
;
BOOL
_initialized
;
}
...
...
@@ -83,6 +85,9 @@ void FlutterInit(int argc, const char* argv[]) {
reinterpret_cast
<
CAEAGLLayer
*>
(
self
.
view
.
layer
));
_platformView
->
SetupResourceContextOnIOThread
();
_platformPlugin
.
reset
([[
FlutterPlatformPlugin
alloc
]
init
]);
[
self
addMessageListener
:
_platformPlugin
.
get
()];
[
self
setupNotificationCenterObservers
];
[
self
connectToEngineAndLoad
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录