浏览代码

Merge branch 'master' into layout

/main
Yuncong Zhang 5 年前
当前提交
705aea72
共有 10 个文件被更改,包括 616 次插入9 次删除
  1. 4
      Runtime/Plugins/platform/ios/UIWidgetsViewController.mm
  2. 2
      Runtime/painting/decoration_image.cs
  3. 3
      Runtime/rendering/image.cs
  4. 13
      Runtime/widgets/scrollbar.cs
  5. 19
      Runtime/Plugins/platform/ios/UIWidgetsDevice.h
  6. 27
      Runtime/Plugins/platform/ios/UIWidgetsDevice.h.meta
  7. 145
      Runtime/Plugins/platform/ios/UIWidgetsDevice.mm
  8. 37
      Runtime/Plugins/platform/ios/UIWidgetsDevice.mm.meta
  9. 364
      Runtime/widgets/fade_in_image.cs
  10. 11
      Runtime/widgets/fade_in_image.cs.meta

4
Runtime/Plugins/platform/ios/UIWidgetsViewController.mm


#include "UIWidgetsViewController.h"
#include "UIWidgetsMessageManager.h"
#include "UIWidgetsDevice.h"
#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>

viewPadding insets = [[UIWidgetsViewController sharedInstance] viewInsets];
viewPadding padding = [[UIWidgetsViewController sharedInstance] padding];
CGFloat scale = [UIScreen mainScreen].scale;
BOOL needDownsample = scale == 3;
BOOL needDownsample = [UIWidgetsDevice NeedScreenDownSample];
metrics.insets_bottom = needDownsample ? insets.bottom * 0.8696 : insets.bottom;
metrics.insets_top = needDownsample ? insets.top * 0.8696 : insets.top;

2
Runtime/painting/decoration_image.cs


Paint paint = new Paint();
if (colorFilter != null) {
paint.colorFilter = colorFilter;
paint.color = colorFilter.color;
paint.blendMode = colorFilter.blendMode;
}
if (sourceSize != destinationSize) {

3
Runtime/rendering/image.cs


this._alignment = alignment ?? Alignment.center;
this._invertColors = invertColors;
this._filterMode = filterMode;
this._updateColorFilter();
}
Image _image;

}
this._color = value;
this._updateColorFilter();
this.markNeedsPaint();
}
}

}
this._colorBlendMode = value;
this._updateColorFilter();
this.markNeedsPaint();
}
}

13
Runtime/widgets/scrollbar.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;

this.minLength * (((inside / viewport) - 0.8f) / 0.2f)
);
}
}
float fractionPast = before / (before + after);
float thumbOffset = (before + after > 0.0)
? fractionPast * (viewport - thumbExtent - 2 * this.mainAxisMargin) + this.mainAxisMargin
: this.mainAxisMargin;
float fractionPast = before / (before + after);
float thumbOffset = (before + after > 0.0)
? fractionPast * (viewport - thumbExtent - 2 * this.mainAxisMargin) + this.mainAxisMargin
: this.mainAxisMargin;
painter(canvas, size, thumbOffset, thumbExtent);
painter(canvas, size, thumbOffset, thumbExtent);
}
}
public override void dispose() {

19
Runtime/Plugins/platform/ios/UIWidgetsDevice.h


//
// UIWidgetsDevice.h
// Unity-iPhone
//
// Created by Xingwei Zhu on 2019/6/24.
//
#ifndef UIWidgetsDevice_h
#define UIWidgetsDevice_h
@interface UIWidgetsDevice : NSObject
+(NSString *) deviceName;
+(BOOL) NeedScreenDownSample;
@end
#endif /* UIWidgetsDevice_h */

27
Runtime/Plugins/platform/ios/UIWidgetsDevice.h.meta


fileFormatVersion: 2
guid: e20d98cc2b0874d97a54ce01aabf3370
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

145
Runtime/Plugins/platform/ios/UIWidgetsDevice.mm


//
// UIWidgetsDevice.m
// Unity-iPhone
//
// Created by Xingwei Zhu on 2019/6/24.
//
#include "UIWidgetsDevice.h"
#import <sys/utsname.h>
static NSString* _deviceName = nil;
@implementation UIWidgetsDevice
+ (NSString *) deviceName
{
if (_deviceName != nil) {
return _deviceName;
}
struct utsname systemInfo;
uname(&systemInfo);
NSString* code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSDictionary* deviceNamesByCode = @{
@"i386" : @"Simulator",
@"x86_64" : @"Simulator",
@"iPod1,1" : @"iPod Touch", // (Original)
@"iPod2,1" : @"iPod Touch", // (Second Generation)
@"iPod3,1" : @"iPod Touch", // (Third Generation)
@"iPod4,1" : @"iPod Touch", // (Fourth Generation)
@"iPod7,1" : @"iPod Touch", // (6th Generation)
@"iPhone1,1" : @"iPhone", // (Original)
@"iPhone1,2" : @"iPhone", // (3G)
@"iPhone2,1" : @"iPhone", // (3GS)
@"iPad1,1" : @"iPad", // (Original)
@"iPad2,1" : @"iPad 2", //
@"iPad3,1" : @"iPad", // (3rd Generation)
@"iPhone3,1" : @"iPhone 4", // (GSM)
@"iPhone3,3" : @"iPhone 4", // (CDMA/Verizon/Sprint)
@"iPhone4,1" : @"iPhone 4S", //
@"iPhone5,1" : @"iPhone 5", // (model A1428, AT&T/Canada)
@"iPhone5,2" : @"iPhone 5", // (model A1429, everything else)
@"iPad3,4" : @"iPad", // (4th Generation)
@"iPad2,5" : @"iPad Mini", // (Original)
@"iPhone5,3" : @"iPhone 5C", // (model A1456, A1532 | GSM)
@"iPhone5,4" : @"iPhone 5C", // (model A1507, A1516, A1526 (China), A1529 | Global)
@"iPhone6,1" : @"iPhone 5S", // (model A1433, A1533 | GSM)
@"iPhone6,2" : @"iPhone 5S", // (model A1457, A1518, A1528 (China), A1530 | Global)
@"iPhone7,1" : @"iPhone 6 Plus", //
@"iPhone7,2" : @"iPhone 6", //
@"iPhone8,1" : @"iPhone 6S", //
@"iPhone8,2" : @"iPhone 6S Plus", //
@"iPhone8,4" : @"iPhone SE", //
@"iPhone9,1" : @"iPhone 7", //
@"iPhone9,3" : @"iPhone 7", //
@"iPhone9,2" : @"iPhone 7 Plus", //
@"iPhone9,4" : @"iPhone 7 Plus", //
@"iPhone10,1": @"iPhone 8", // CDMA
@"iPhone10,4": @"iPhone 8", // GSM
@"iPhone10,2": @"iPhone 8 Plus", // CDMA
@"iPhone10,5": @"iPhone 8 Plus", // GSM
@"iPhone10,3": @"iPhone X", // CDMA
@"iPhone10,6": @"iPhone X", // GSM
@"iPhone11,2": @"iPhone XS", //
@"iPhone11,4": @"iPhone XS Max", //
@"iPhone11,6": @"iPhone XS Max", // China
@"iPhone11,8": @"iPhone XR", //
@"iPad4,1" : @"iPad Air", // 5th Generation iPad (iPad Air) - Wifi
@"iPad4,2" : @"iPad Air", // 5th Generation iPad (iPad Air) - Cellular
@"iPad4,4" : @"iPad Mini", // (2nd Generation iPad Mini - Wifi)
@"iPad4,5" : @"iPad Mini", // (2nd Generation iPad Mini - Cellular)
@"iPad4,7" : @"iPad Mini", // (3rd Generation iPad Mini - Wifi (model A1599))
@"iPad6,7" : @"iPad Pro (12.9\")", // iPad Pro 12.9 inches - (model A1584)
@"iPad6,8" : @"iPad Pro (12.9\")", // iPad Pro 12.9 inches - (model A1652)
@"iPad6,3" : @"iPad Pro (9.7\")", // iPad Pro 9.7 inches - (model A1673)
@"iPad6,4" : @"iPad Pro (9.7\")"
};
_deviceName = [deviceNamesByCode objectForKey:code];
if (!_deviceName) {
if ([code rangeOfString:@"iPod"].location != NSNotFound) {
_deviceName = @"iPod Touch";
}
else if([code rangeOfString:@"iPad"].location != NSNotFound) {
_deviceName = @"iPad";
}
else if([code rangeOfString:@"iPhone"].location != NSNotFound){
_deviceName = @"iPhone";
}
else {
_deviceName = @"Unknown";
}
}
if ([_deviceName isEqualToString:@"Simulator"]) {
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
switch ((int)[[UIScreen mainScreen] nativeBounds].size.height) {
//iPhone 5 or 5S or 5C
case 1136:
_deviceName = @"iPhone 5 Simulator";
break;
//iPhone 6 or 6S or 7 or 8
case 1334:
_deviceName = @"iPhone 6 Simulator";
break;
//iPhone 6+ or 6S+ or 7+ or 8+
case 1920:
_deviceName = @"iPhone 6 Plus Simulator";
break;
//iPhone 6+ or 6S+ or 7+ or 8+
case 2208:
_deviceName = @"iPhone 6 Plus Simulator";
break;
//iPhone X or XS
case 2436:
_deviceName = @"iPhone X Simulator";
break;
//iPhone XS Max
case 2688:
_deviceName = @"iPhone XS Max Simulator";
break;
//iPhone XR
case 1792:
_deviceName = @"iPhone XR Simulator";
break;
default:
_deviceName = @"Unknown Simulator";
break;
}
}
}
return _deviceName;
}
+ (BOOL) NeedScreenDownSample
{
return [[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 6 Plus"] ||
[[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 6S Plus"] ||
[[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 7 Plus"] ||
[[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 8 Plus"];
}
@end

37
Runtime/Plugins/platform/ios/UIWidgetsDevice.mm.meta


fileFormatVersion: 2
guid: ebe1b83c142fc4eb2b0a2958dd29e9bd
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings: {}
- first:
tvOS: tvOS
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

364
Runtime/widgets/fade_in_image.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
namespace Unity.UIWidgets.widgets {
public class FadeInImage : StatefulWidget {
public FadeInImage(
ImageProvider placeholder,
ImageProvider image,
TimeSpan? fadeOutDuration = null,
Curve fadeOutCurve = null,
TimeSpan? fadeInDuration = null,
Curve fadeInCurve = null,
float? width = null,
float? height = null,
BoxFit? fit = null,
Alignment alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat,
Key key = null
) : base(key) {
D.assert(placeholder != null);
D.assert(image != null);
D.assert(fadeOutDuration != null);
D.assert(fadeOutCurve != null);
D.assert(fadeInDuration != null);
D.assert(fadeInCurve != null);
D.assert(alignment != null);
this.placeholder = placeholder;
this.image = image;
this.width = width;
this.height = height;
this.fit = fit;
this.fadeOutDuration = fadeOutDuration ?? TimeSpan.FromMilliseconds(300);
this.fadeOutCurve = fadeOutCurve ?? Curves.easeOut;
this.fadeInDuration = fadeInDuration ?? TimeSpan.FromMilliseconds(700);
this.fadeInCurve = fadeInCurve ?? Curves.easeIn;
this.alignment = alignment ?? Alignment.center;
this.repeat = repeat;
}
public static FadeInImage memoryNetwork(
byte[] placeholder,
string image,
float placeholderScale = 1.0f,
float imageScale = 1.0f,
TimeSpan? fadeOutDuration = null,
Curve fadeOutCurve = null,
TimeSpan? fadeInDuration = null,
Curve fadeInCurve = null,
float? width = null,
float? height = null,
BoxFit? fit = null,
Alignment alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat,
Key key = null
) {
D.assert(placeholder != null);
D.assert(image != null);
D.assert(fadeOutDuration != null);
D.assert(fadeOutCurve != null);
D.assert(fadeInDuration != null);
D.assert(fadeInCurve != null);
D.assert(alignment != null);
var memoryImage = new MemoryImage(placeholder, placeholderScale);
var networkImage = new NetworkImage(image, imageScale);
return new FadeInImage(
memoryImage,
networkImage,
fadeOutDuration,
fadeOutCurve,
fadeInDuration,
fadeInCurve,
width, height,
fit,
alignment,
repeat,
key
);
}
public static FadeInImage assetNetwork(
string placeholder,
string image,
AssetBundle bundle = null,
float? placeholderScale = null,
float imageScale = 1.0f,
TimeSpan? fadeOutDuration = null,
Curve fadeOutCurve = null,
TimeSpan? fadeInDuration = null,
Curve fadeInCurve = null,
float? width = null,
float? height = null,
BoxFit? fit = null,
Alignment alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat,
Key key = null
) {
D.assert(placeholder != null);
D.assert(image != null);
D.assert(fadeOutDuration != null);
D.assert(fadeOutCurve != null);
D.assert(fadeInDuration != null);
D.assert(fadeInCurve != null);
D.assert(alignment != null);
var imageProvider = placeholderScale != null
? new ExactAssetImage(placeholder, bundle: bundle, scale: placeholderScale ?? 1.0f)
: (ImageProvider) new AssetImage(placeholder, bundle: bundle);
var networkImage = new NetworkImage(image, imageScale);
return new FadeInImage(
imageProvider,
networkImage,
fadeOutDuration,
fadeOutCurve,
fadeInDuration,
fadeInCurve,
width, height,
fit,
alignment,
repeat,
key
);
}
public readonly ImageProvider placeholder;
public readonly ImageProvider image;
public readonly TimeSpan fadeOutDuration;
public readonly Curve fadeOutCurve;
public readonly TimeSpan fadeInDuration;
public readonly Curve fadeInCurve;
public readonly float? width;
public readonly float? height;
public readonly BoxFit? fit;
public readonly Alignment alignment;
public readonly ImageRepeat repeat;
public override State createState() {
return new _FadeInImageState();
}
}
enum FadeInImagePhase {
start,
waiting,
fadeOut,
fadeIn,
completed
}
delegate void _ImageProviderResolverListener();
class _ImageProviderResolver {
public _ImageProviderResolver(
_FadeInImageState state,
_ImageProviderResolverListener listener
) {
this.state = state;
this.listener = listener;
}
readonly _FadeInImageState state;
readonly _ImageProviderResolverListener listener;
FadeInImage widget {
get { return this.state.widget; }
}
public ImageStream _imageStream;
public ImageInfo _imageInfo;
public void resolve(ImageProvider provider) {
ImageStream oldImageStream = this._imageStream;
Size size = null;
if (this.widget.width != null && this.widget.height != null) {
size = new Size((int) this.widget.width, (int) this.widget.height);
}
this._imageStream = provider.resolve(ImageUtils.createLocalImageConfiguration(this.state.context, size));
D.assert(this._imageStream != null);
if (this._imageStream.key != oldImageStream?.key) {
oldImageStream?.removeListener(this._handleImageChanged);
this._imageStream.addListener(this._handleImageChanged);
}
}
void _handleImageChanged(ImageInfo imageInfo, bool synchronousCall) {
this._imageInfo = imageInfo;
this.listener();
}
public void stopListening() {
this._imageStream?.removeListener(this._handleImageChanged);
}
}
class _FadeInImageState : TickerProviderStateMixin<FadeInImage> {
_ImageProviderResolver _imageResolver;
_ImageProviderResolver _placeholderResolver;
AnimationController _controller;
Animation<float> _animation;
FadeInImagePhase _phase = FadeInImagePhase.start;
public override void initState() {
this._imageResolver = new _ImageProviderResolver(state: this, this._updatePhase);
this._placeholderResolver = new _ImageProviderResolver(state: this, listener: () => {
this.setState(() => {
// Trigger rebuild to display the placeholder image
});
});
this._controller = new AnimationController(
value: 1.0f,
vsync: this
);
this._controller.addListener(() => {
this.setState(() => {
// Trigger rebuild to update opacity value.
});
});
this._controller.addStatusListener(status => { this._updatePhase(); });
base.initState();
}
public override void didChangeDependencies() {
this._resolveImage();
base.didChangeDependencies();
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
FadeInImage fadeInImage = oldWidget as FadeInImage;
if (this.widget.image != fadeInImage.image || this.widget.placeholder != fadeInImage.placeholder) {
this._resolveImage();
}
}
void _resolveImage() {
this._imageResolver.resolve(this.widget.image);
if (this._isShowingPlaceholder) {
this._placeholderResolver.resolve(this.widget.placeholder);
}
if (this._phase == FadeInImagePhase.start) {
this._updatePhase();
}
}
void _updatePhase() {
this.setState(() => {
switch (this._phase) {
case FadeInImagePhase.start:
if (this._imageResolver._imageInfo != null) {
this._phase = FadeInImagePhase.completed;
}
else {
this._phase = FadeInImagePhase.waiting;
}
break;
case FadeInImagePhase.waiting:
if (this._imageResolver._imageInfo != null) {
this._controller.duration = this.widget.fadeOutDuration;
this._animation = new CurvedAnimation(
parent: this._controller,
curve: this.widget.fadeOutCurve
);
this._phase = FadeInImagePhase.fadeOut;
this._controller.reverse(1.0f);
}
break;
case FadeInImagePhase.fadeOut:
if (this._controller.status == AnimationStatus.dismissed) {
// Done fading out placeholder. Begin target image fade-in.
this._controller.duration = this.widget.fadeInDuration;
this._animation = new CurvedAnimation(
parent: this._controller,
curve: this.widget.fadeInCurve
);
this._phase = FadeInImagePhase.fadeIn;
this._placeholderResolver.stopListening();
this._controller.forward(0.0f);
}
break;
case FadeInImagePhase.fadeIn:
if (this._controller.status == AnimationStatus.completed) {
// Done finding in new image.
this._phase = FadeInImagePhase.completed;
}
break;
case FadeInImagePhase.completed:
// Nothing to do.
break;
}
});
}
public override void dispose() {
this._imageResolver.stopListening();
this._placeholderResolver.stopListening();
this._controller.dispose();
base.dispose();
}
bool _isShowingPlaceholder {
get {
switch (this._phase) {
case FadeInImagePhase.start:
case FadeInImagePhase.waiting:
case FadeInImagePhase.fadeOut:
return true;
case FadeInImagePhase.fadeIn:
case FadeInImagePhase.completed:
return false;
}
return true;
}
}
ImageInfo _imageInfo {
get {
return this._isShowingPlaceholder
? this._placeholderResolver._imageInfo
: this._imageResolver._imageInfo;
}
}
public override Widget build(BuildContext context) {
D.assert(this._phase != FadeInImagePhase.start);
ImageInfo imageInfo = this._imageInfo;
return new RawImage(
image: imageInfo?.image,
width: this.widget.width,
height: this.widget.height,
scale: imageInfo?.scale ?? 1.0f,
color: Color.fromRGBO(255, 255, 255, this._animation?.value ?? 1.0f),
colorBlendMode: BlendMode.modulate,
fit: this.widget.fit,
alignment: this.widget.alignment,
repeat: this.widget.repeat
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<FadeInImagePhase>("phase", this._phase));
properties.add(new DiagnosticsProperty<ImageInfo>("pixels", this._imageInfo));
properties.add(new DiagnosticsProperty<ImageStream>("image stream", this._imageResolver._imageStream));
properties.add(new DiagnosticsProperty<ImageStream>("placeholder stream",
this._placeholderResolver._imageStream));
}
}
}

11
Runtime/widgets/fade_in_image.cs.meta


fileFormatVersion: 2
guid: ffe6fc92113b04df4880137d3a6fa315
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存