浏览代码

Merge pull request #57 from Unity-Technologies/siyaoH/1.17/fix

fix image
/siyaoH-1.17-PlatformMessage
GitHub 4 年前
当前提交
5b316c39
共有 5 个文件被更改,包括 103 次插入91 次删除
  1. 5
      Samples/UIWidgetsSamples_2019_4/Assets/Script/ImageTest.cs
  2. 6
      com.unity.uiwidgets/Runtime/painting/image_cache.cs
  3. 10
      com.unity.uiwidgets/Runtime/painting/image_provider.cs
  4. 3
      com.unity.uiwidgets/Runtime/widgets/disposable_build_context.cs
  5. 170
      com.unity.uiwidgets/Runtime/widgets/image.cs

5
Samples/UIWidgetsSamples_2019_4/Assets/Script/ImageTest.cs


public override Widget build(BuildContext context)
{
return new Container(
color: Color.black,
child: new Column(
children: new List<Widget>
{

new GestureDetector(
onTap: () => { setState(() => { frame += 1; }); },
child: new Container(
color: Color.black,
color: Color.white,
style: new TextStyle(fontWeight: FontWeight.w100))
style: new TextStyle(fontWeight: FontWeight.w700))
)
)
}

6
com.unity.uiwidgets/Runtime/painting/image_cache.cs


}
void _touch(Object key, _CachedImage image) {
D.assert(foundation_.kReleaseMode);
// D.assert(foundation_.kReleaseMode);
if (image.sizeBytes != null && image.sizeBytes <= maximumSizeBytes) {
_currentSizeBytes += image.sizeBytes ?? 0;
_cache[key] = image;

return image.completer;
}
_CachedImage liveImage = _liveImages[key];
_liveImages.TryGetValue(key, out var liveImage);
if (liveImage != null) {
_touch(key, liveImage);
return liveImage.completer;

}
if (untrackedPendingImage == null) {
_touch(key, image);
_touch(key, cachedImage);
}
listenedOnce = true;

10
com.unity.uiwidgets/Runtime/painting/image_provider.cs


);
return null;
});
return null;
return null;
}
);

void resolveStreamForKey(ImageConfiguration configuration, ImageStream stream, T key,
ImageErrorListener handleError) {
if (stream.completer != null) {
ImageStreamCompleter completerEdge = PaintingBinding.instance.imageCache.putIfAbsent(
key,

int width = 0,
int height = 0
) {
D.assert(width != null || height != null);
this.imageProvider = imageProvider;
this.width = width;
this.height = height;

public readonly int height;
public static ImageProvider resizeIfNeeded(int cacheWidth, int cacheHeight, ImageProvider<object> provider) {
public static ImageProvider resizeIfNeeded(int? cacheWidth, int? cacheHeight, ImageProvider provider) {
return new ResizeImage(provider, width: cacheWidth, height: cacheHeight);
return new ResizeImage((ImageProvider<object>) provider, width: cacheWidth.Value, height: cacheHeight.Value);
}
return provider;

Future<Codec> _loadAsync(FileImage key, DecoderCallback decode) {
byte[] bytes = File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, key.file));
if (bytes != null && bytes.Length > 0 ) {
if (bytes != null && bytes.Length > 0) {
return decode(bytes);
}

3
com.unity.uiwidgets/Runtime/widgets/disposable_build_context.cs


public class DisposableBuildContext<T> where T : State{
public DisposableBuildContext(T state) {
public DisposableBuildContext(T _state) {
this._state = _state;
}
T _state;

170
com.unity.uiwidgets/Runtime/widgets/image.cs


return new ImageConfiguration(
bundle: DefaultAssetBundle.of(context),
devicePixelRatio: MediaQuery.of(context, nullOk: true)?.devicePixelRatio ?? 1.0f,
//locale: Localizations.localeOf(context, nullOk: true),
locale: Localizations.localeOf(context, nullOk: true),
size: size,
platform: Application.platform
);

}
}
public delegate Widget ImageFrameBuilder (
BuildContext context,
Widget child,
int frame,
bool wasSynchronouslyLoaded
public delegate Widget ImageFrameBuilder(
BuildContext context,
Widget child,
int frame,
bool wasSynchronouslyLoaded
// [!!!] class ImageChunkEvent is missing
BuildContext context,
Widget child//,
//ImageChunkEvent loadingProgress
BuildContext context,
Widget child,
ImageChunkEvent loadingProgress
public class Image : StatefulWidget {
public Image(
Key key = null,

bool gaplessPlayback = false,
FilterQuality filterQuality = FilterQuality.low,
IDictionary<string, string> headers = null,
int cacheWidth = default,
int cacheHeight = default
int? cacheWidth = null,
int? cacheHeight = null
var networkImage = new NetworkImage(src, scale, headers);//image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, NetworkImage(src, scale: scale, headers: headers));
var image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight,
new NetworkImage(src, scale: scale, headers: headers));
image: networkImage,
image: image,
frameBuilder: frameBuilder,
loadingBuilder: loadingBuilder,
errorBuilder: errorBuilder,

Rect centerSlice = null,
bool gaplessPlayback = false,
FilterQuality filterQuality = FilterQuality.low,
int cacheWidth = default,
int cacheHeight = default
int? cacheWidth = null,
int? cacheHeight = null
var fileImage = new FileImage(file, scale);//ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, FileImage(file, scale: scale));
var fileImage = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, new FileImage(file, scale: scale));
return new Image(
key: key,
image: fileImage,

Rect centerSlice = null,
bool gaplessPlayback = false,
FilterQuality filterQuality = FilterQuality.low,
int cacheWidth = default,
int cacheHeight = default
int? cacheWidth = default,
int? cacheHeight = null
) {
/*image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, scale != null
? ExactAssetImage(name, bundle: bundle, scale: scale, package: package)

Rect centerSlice = null,
bool gaplessPlayback = false,
FilterQuality filterQuality = FilterQuality.low,
int cacheWidth = default,
int cacheHeight = default
int? cacheWidth = default,
int? cacheHeight = null
) {
// ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, MemoryImage(bytes, scale: scale));
var memoryImage = new MemoryImage(bytes, scale);

properties.add(new EnumProperty<ImageRepeat>("repeat", repeat, defaultValue: ImageRepeat.noRepeat));
properties.add(new DiagnosticsProperty<Rect>("centerSlice", centerSlice,
defaultValue: foundation_.kNullDefaultValue));
properties.add(new EnumProperty<FilterQuality>("filterQuality", filterQuality, foundation_.kNullDefaultValue));
properties.add(new EnumProperty<FilterQuality>("filterQuality", filterQuality,
foundation_.kNullDefaultValue));
public class _ImageState : State<Image> ,WidgetsBindingObserver{
public class _ImageState : State<Image>, WidgetsBindingObserver {
//ImageChunkEvent _loadingProgress;
ImageChunkEvent _loadingProgress;
bool _isListeningToStream = false;
bool _invertColors;
int _frameNumber;

StackTrace _lastStack;
public override void initState() {
base.initState();
WidgetsBinding.instance.addObserver(this);

_scrollAwareContext.dispose();
base.dispose();
}
public override void didChangeDependencies() {
_updateInvertColors();
_resolveImage();

Image image = (Image) oldWidget;
if (_isListeningToStream &&
(widget.loadingBuilder == null) != (image.loadingBuilder == null)) {
/*_imageStream.removeListener(_getListener(image.loadingBuilder));
_imageStream.addListener(_getListener());*/
_imageStream.removeListener(_getListener(image.loadingBuilder));
_imageStream.addListener(_getListener());
/*public override void didChangeAccessibilityFeatures() {
base.didChangeAccessibilityFeatures();
setState(() => {

void _updateInvertColors() {
_invertColors = MediaQuery.of(context, nullOk: true)?.invertColors
?? false;

D.assert(newStream != null);
_updateSourceStream(newStream);
}
/*ImageStreamListener _getListener(ImageLoadingBuilder loadingBuilder = null) {
loadingBuilder ??= widget.loadingBuilder;
void _onError(Exception error) {
setState(() => {
_lastException = error;
// _lastStack = stackTrace;
});
}
ImageStreamListener _getListener(ImageLoadingBuilder loadingBuilder = null) {
loadingBuilder = loadingBuilder ?? widget.loadingBuilder;
ImageChunkListener onChunk = null;
if (loadingBuilder == null) {
onChunk = _handleImageChunk;
}
ImageErrorListener onError = null;
if (widget.errorBuilder != null) {
onError = (Exception error) => {
setState(() => {
_lastException = error;
// _lastStack = stackTrace;
});
};
}
onChunk: loadingBuilder == null ? null : _handleImageChunk,
onError: widget.errorBuilder != null
? (dynamic error, StackTrace stackTrace) => {
setState(() => {
_lastException = error;
_lastStack = stackTrace;
});
}
: null
);
}*/
onChunk: onChunk,
onError: onError
);
}
/*void _handleImageFrame(ImageInfo imageInfo, bool synchronousCall) {
setState(() =>{
void _handleImageFrame(ImageInfo imageInfo, bool synchronousCall) {
setState(() => {
_imageInfo = imageInfo;
_loadingProgress = null;
_frameNumber = _frameNumber == null ? 0 : _frameNumber + 1;

void _handleImageChunk(ImageChunkEvent _event) {
D.assert(widget.loadingBuilder != null);
setState(() => {
_loadingProgress = _event;
});
}*/
setState(() => { _loadingProgress = _event; });
}
// TODO: update
// if (_isListeningToStream) {
// _imageStream.removeListener(_handleImageChanged);
// }
if (_isListeningToStream) {
_imageStream.removeListener(_getListener());
}
// TODO: update
// _imageStream = newStream;
// if (_isListeningToStream) {
// _imageStream.addListener(_handleImageChanged);
// }
_imageStream = newStream;
if (_isListeningToStream) {
_imageStream.addListener(_getListener());
}
}
void _listenToStream() {

// TODO: update
// _imageStream.addListener(_handleImageChanged);
// _isListeningToStream = true;
_imageStream.addListener(_getListener());
_isListeningToStream = true;
}
void _stopListeningToStream() {

// TODO: update
// _imageStream.removeListener(_handleImageChanged);
_imageStream.removeListener(_getListener());
if (_lastException != null) {
if (_lastException != null) {
RawImage image = new RawImage(
Widget image = new RawImage(
image: _imageInfo?.image,
width: widget.width,
height: widget.height,

invertColors: _invertColors,
filterQuality: widget.filterQuality
);
/*if (widget.frameBuilder != null)
if (widget.frameBuilder != null)
image = widget.loadingBuilder(context, image, _loadingProgress);*/
image = widget.loadingBuilder(context, image, _loadingProgress);
return image;
}

description.add(new DiagnosticsProperty<bool>("wasSynchronouslyLoaded", _wasSynchronouslyLoaded));
}
public void didChangeMetrics() {
setState();
}

正在加载...
取消
保存