private bool BuildAttachmentImageNodeIfNeeded(nfloat width, out IASLayoutElement layoutElement) { if (_viewModelRef.Target == null || !_viewModelRef.Target.HasAttachment) { layoutElement = null; return(false); } var maxWidth = width - 50 - 73 - 17 - (nfloat)AvatarSize; if (_attachmentImageNode.Image != null) { _attachmentImageNode.Style.PreferredSize = CalculateAttachmentImageNodeSize( _attachmentImageNode.Image.Size, maxWidth); layoutElement = _attachmentImageNode; } else { var placeholderImage = UIImage.FromBundle(StyleHelper.Style.AttachmentImagePlaceholderBundleName); var placeholderImageNode = new ASImageNode { Image = placeholderImage }; placeholderImageNode.Style.PreferredSize = CalculateAttachmentImageNodeSize(placeholderImage.Size, maxWidth); layoutElement = placeholderImageNode; } return(true); }
private IASLayoutElement BuildMessageBodyWithBackground(IASLayoutElement messageBodyNode) { var backgroundImageBundleName = _isMyMessage ? StyleHelper.Style.BubbleMineBoundleName : StyleHelper.Style.BubbleOtherBoundleName; var backgroundImage = UIImage.FromBundle(backgroundImageBundleName) ?.CreateResizableImage(new UIEdgeInsets(36, 20, 10, 20)); var backgroundNode = new ASImageNode { Image = backgroundImage }; return(ASBackgroundLayoutSpec.BackgroundLayoutSpecWithChild(messageBodyNode, backgroundNode)); }
public static async Task LoadImageAsync(this ASImageNode imageNode, string url) { if (string.IsNullOrEmpty(url)) { return; } var expr = ImageService.Instance.LoadUrl(url); try { var image = await expr.AsUIImageAsync().ConfigureAwait(false); imageNode.Image = image; } catch { // do nothing } }
public static async void LoadImageWithTextPlaceholder(this ASImageNode imageView, string url, string name, AvatarStyles styles) { Execute.BeginOnUIThread(() => { imageView.Image = CreateAvatarWithTextPlaceholder(name, styles); }); if (string.IsNullOrEmpty(url)) { return; } var expr = ImageService.Instance .LoadUrl(url) .DownSampleInDip(styles.Size.Width, styles.Size.Height); UIImage image = null; try { image = await expr.AsUIImageAsync().ConfigureAwait(false); } catch { // do nothing } if (image != null) { Execute.BeginOnUIThread(() => { imageView.Image = image; }); } }