Xamarin.Forms ScrollView ScrollToAsync() results in blank content on iOS - xamarin.forms

Background
We have a page where we have a bound RepeaterView within a ScrollView. We're adding Questions to the bound collection as the user answers questions (the aim is to give a series of questions, scrolling off the top as the user progresses).
We want the ScrollView to scroll to the bottom as we add Questions.
To do this, I've created an Event which we raise when we add a Question, and added a handler in the Page. I'm subscribing/unsubscribing on the Appearing/Disappearing events for the page to avoid memory leaks etc.
The Problem
On Android this works fine. But on iOS, the ScrollView goes blank. However, if I background the app and bring it back to the foreground (by tapping the Home button and then the app icon, the screen then refreshes.
Therefore it appears that the Page isn't being refreshed properly by my code.
My XAML code:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MvvmCross.Forms.Presenters.Attributes;
using MyApp.Mobile.PageModels.Claims.Medical;
using MyApp.Mobile.Pages.Base;
using Xamarin.Forms;
namespace MyApp.Mobile.Pages.Claims.Medical
{
[MvxContentPagePresentation(NoHistory = true)]
public partial class ClaimConditionPage : BaseContentPage<ClaimConditionPageModel>
{
public ClaimConditionPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
if (BindingContext != null)
{
ClaimConditionPageModel model = (ClaimConditionPageModel)this.BindingContext.DataContext;
model.QuestionAdded += Model_QuestionAdded;
}
base.OnAppearing();
}
protected override void OnDisappearing()
{
ClaimConditionPageModel model = (ClaimConditionPageModel)this.BindingContext.DataContext;
model.QuestionAdded -= Model_QuestionAdded;
base.OnDisappearing();
}
void Model_QuestionAdded(object sender, EventArgs e)
{
Device.BeginInvokeOnMainThread(async () =>
{
await QuestionScrollView.ScrollToAsync(0, QuestionScrollView.Content.Height, false);
});
}
}
}
I've seen suggestions of adding a Task.Delay() to allow the UI to catch up - but this didn't work.
Note that this is only on iOS.
I note that there is this bug, but I don't think this is my problem. The ScrollView does scroll, but the display goes blank.
Versions
Xamarin.Forms 3.4.0.1029999
=== Visual Studio Community 2017 for Mac ===
Version 7.8.2 (build 1)
Installation UUID: 650b4c91-c7f5-4ee5-ad70-6f178f314906
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.0.0.0 ( / b40230c0)
Package version: 516000221
=== Mono Framework MDK ===
Runtime:
Mono 5.16.0.221 (2018-06/b63e5378e38) (64-bit)
Package version: 516000221
=== NuGet ===
Version: 4.8.0.5385
=== .NET Core ===
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.8
2.1.5
2.1.2
2.1.1
2.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.504/Sdks
SDK Versions:
2.1.504
2.1.403
2.1.302
2.1.301
2.1.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.16.0/lib/mono/msbuild/15.0/bin/Sdks
=== Xamarin.Profiler ===
Version: 1.6.4
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
=== Updater ===
Version: 11
=== Apple Developer Tools ===
Xcode 10.1 (14460.46)
Build 10B61
=== Xamarin.Mac ===
Version: 5.2.1.15 (Visual Studio Community)
Hash: d60abd198
Branch:
Build date: 2019-02-01 12:23:30-0500
=== Xamarin.iOS ===
Version: 12.2.1.15 (Visual Studio Community)
Hash: d60abd198
Branch: d15-9
Build date: 2019-02-01 12:23:29-0500
=== Xamarin.Android ===
Version: 9.1.8.0 (Visual Studio Community)
Android SDK: /Users/jameslavery/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
2.3 (API level 10)
4.0.3 (API level 15)
4.1 (API level 16)
4.3 (API level 18)
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)
SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 26.0.2
=== Microsoft Mobile OpenJDK ===
Java SDK: /Users/jameslavery/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
=== Android Device Manager ===
Version: 7.8.1.0
Hash: 8924ea4a
=== Xamarin Inspector ===
Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1
=== Build Information ===
Release ID: 708020001
Git revision: 13e0e5b7e85ffe742957e6f204bab5c06c644f0e
Build date: 2019-02-27 19:33:14+00
Build branch: release-7.8
Xamarin extensions: 23eaa7c9cdc9a3f55be7bb87b485a790ec82ef25
=== Operating System ===
Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
Fri Nov 2 20:43:16 PDT 2018
root:xnu-4570.71.17~1/RELEASE_X86_64 x86_64
=== Enabled user installed extensions ===
LiveXAML 1.3.31
MFractor 3.7.10
MvvmCross Template pack 2.0.1
NuGet Package Management Extensions 0.15
Template Creator 0.4
Redth's Addins 1.0.9
Internet of Things (IoT) development (Preview) 7.5

It appears that there is a bug on iOS with this ScrollToAsync signature.
Changing to the ScrollToAsync which takes an Element fixes it.
Interestingly, I need aTask.Delay(10) to allow the Repeater's size to update before the ScrollToAsync is called. The resulting code is:
void Model_QuestionAdded(object sender, EventArgs e)
{
Device.BeginInvokeOnMainThread(async () =>
{
await Task.Delay(10);
await QuestionScrollView.ScrollToAsync(QuestionRepeater, ScrollToPosition.End, true);
});
}
It would be good to avoid the Task.Delay() if possible - I don't like this sort of thing because timings differ on devices, and I'm likely to find the delay isn't long enough on slower/faster devices.

Related

Different behavior reading the registry when opening the solution in VS2015 and VS2017

I have a solution that I wanted to upgrade from VS 2015 to VS 2017.
The program in the solution will read values from registry.
For example, the path is : Computer\HKEY_LOCAL_MACHINE\SOFTWARE\MYPROGRAM
When opening the solution using VS 2015, it can read the registry successfully.
But when opening the solution using VS 2017, it seems to read the registry from Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\MYPROGRAM
The code
private const string REG_KEY = "Software\\MYPROGRAM";
public static string GetEnvironment()
{
if (SystemEnvironment == string.Empty)
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey(REG_KEY);
if (rk == null)
throw new Exception("Unable to open registry key");
else
try
{
SystemEnvironment = rk.GetValue("ENVIRONMENT").ToString();
if (SystemEnvironment == null)
throw new Exception("Unable to retrieve Environment");
}
finally
{ rk.Close(); }
}
return SystemEnvironment;
}
It's the same code, the difference is the VS version.
How to fix the issue?
It turns out that my settings for VS2015 and VS2017 is different.
To solve this, I need to set my Visual Studio to use the 64 bit version of IIS Express.
To do that, Go to Tools > Options > Projects and Solutions > Web Projects > Tick "Use the 64 bit version of IIS Express for web sites and projects".

cloudstack end-user cantg resize volumes

End users (also Domain admins) can't resize Volumes - there is no such option in CS GUI (see img1.PNG) . While Cloudstack Admin is able resize vols (see img2.PNG).
Info: CS version - 4.8.0 HA management servers behind HAProxy with MariaDb Galera. Host: Xenserver.
img1.png:https://files.fm/u/krgxs9b9#/view/img1.PNG
img2.png: https://files.fm/u/krgxs9b9#/view/img2.PNG
This is fixed in 4.9 by the following PR. API allowed end users to resize but the option wasn't available through UI.
https://github.com/apache/cloudstack/pull/1595
In: /usr/share/cloudstack-management/webapps/client/scripts/storage.js
Removing:
if (jsonObj.hypervisor == "KVM" || jsonObj.hypervisor == "XenServer" || jsonObj.hypervisor == "VMware") {
if (jsonObj.state == "Ready" || jsonObj.state == "Allocated") {
allowedActions.push("resize");
}
And adding:
if (jsonObj.state == "Ready" || jsonObj.state == "Allocated") {
allowedActions.push("resize");
}
Also removing: /usr/share/cloudstack-management/webapps/client/scripts/storage.js.gz
Resolves issue

TideSDK Notifications in OSX Lion 10.7.5

I started using the tideSDK for a simple desktop application. Im using the notification api. This works on Windows platforms but not on my OSX Lion 10.7.5.
This is the notification code from the TideSDK docs tideSDK docs
doSomething = () ->
alert "nice!"
notification = Ti.Notification.createNotification(
title: "Notification from App"
message: "Click here for updates!"
timeout: 10
callback: doSomething
icon: "app://img/icon.png"
)
notification.show()
SO like a said this works on Windows, so the code seems to be correct, but not on OSX. Any ideas ?
Im using version 1.4.2 of the developer SDK, according to what I read it supposed to work with Growl
Harry, I'm not too familiar with CoffeeScript, but the following code works for me in 10.7.5 and 10.8.4 - it seems similar to what you have:
function showNotify(title, message) {
var notification = Ti.Notification.createNotification({
'title': title || 'No Title',
'message': message || 'No Message',
'timeout': 10
});
notification.show();
}
showNotify("The Title", "The Message");
Hope it helps.

ARC Retain Cycle appears after updating to iOS 6.1

After updating to iOS 6.1, I'm getting this warning in AFImageRequestOperation.m and AFHTTPClient.m from AFNetworking framework:
Capturing 'operation' strongly in this block is likely to lead to a
retain cycle
Based on this answer, I can fix a retain cycle in ARC by using __weak variables. It is also says
Block will be retained by the captured object
Does anyone know how to solve this?
Thanks.
We are fortunate that XCode 4.6 is showing a warning to avoid this problem
It can be solved by providing a weak reference
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
**__weak AFImageRequestOperation *tempRequestOperation = requestOperation;**
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if (success) {
UIImage *image = responseObject;
if (imageProcessingBlock) {
dispatch_async(image_request_operation_processing_queue(), ^(void) {
UIImage *processedImage = imageProcessingBlock(image);
dispatch_async(**tempRequestOperation**.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) {
success(operation.request, operation.response, processedImage);
});
});
} else {
success(operation.request, operation.response, image);
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failure) {
failure(operation.request, operation.response, error);
}
}];
OK here was the problem. I was keep downloading the Master branch from GitHub and now that I tried downloading AFNetworking from here (version 1.1.0) it doesn't show me the warning anymore.
I don't why the latest commits were not included in the master branch when I downloaded but clearly they've solved these strong refs in blocks warnings while ago.
Always check the website to see the latest released version or sync the latest commit from GitHub :) (It wasn't showing anything in my iOS 6.0 apps but Xcode 4.6 just brought them up)

PluginManager undefined in cordova js

I created a Cordova project in Xcode 4. I add my plugin in the Cordova.plist, but in the cordova.js I get the following error:
in func:Cordova.exec
in the line:
var v = cordova.PluginManager.exec(success, fail, service, action, args);
the cordova.PluginManager is undefined.
Do you know why?
thanks.
I am new to Cordova, but based on what I have seen, you may need to make sure Cordova has loaded. To call the plugin after Cordova has finished loading, do the following in your javascript file:
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
// As an example, you now have the device name, Cordova version, etc. available
alert('Device Name: ' + device.name);
alert('Device Cordova: ' + device.cordova);
alert('Device Platform: ' + device.platform);
alert('Device UUID: ' + device.uuid);
alert('Device Version: ' + device.version);
// Now call plugin, etc.
var v = cordova.PluginManager.exec(success, fail, service, action, args);
}
See http://docs.phonegap.com/en/2.0.0/cordova_device_device.md.html#Device for more information.
The Cordova documentation for iOS plugins provides additional detail.

Resources