RecyclerView scroll to bottom - xamarin

I want to write a Xamarin.UITest that scrolls my RecyclerView to the bottom and taps on the last item in the list. How can I do this?

I figured it out by setting a view in the last item in my RecyclerView ContentDescription="isLast". Then in my test:
app.ScrollDownTo("isLast", "rvId", ScrollStrategy.Gesture, 0.67, 5000, true, TimeSpan.FromSeconds(30));
app.Tap(c => c.Marked("isLast"));
Where rvId is the ID of the RecyclerView. For example, I have a TextView in each item of my RecyclerView, so I set the last one to MyTextView.ContentDescription="isLast" in my RecyclerView.Adapter

Related

Xamarin.UITest RecyclerView wait for items to load

I am trying to write an Xamarin.UITest for my Android project. My app has a "download" UIButton, that when pressed, downloads data and then populates a RecyclerView. Then when a "clear" UIButton is pressed, the RecyclerView is cleared. This is what I tried so far:
app.Tap(c => c.Marked("download_btn"));
app.WaitForElement(x => x.Marked("recycler_item"), "Timed out waiting for items to load", TimeSpan.FromSeconds(5));
app.Tap(c => c.Marked("clear_btn"));
The app.WaitForElement part never finds the items in the RecyclerView, even when they are there. I want to test that there is at least 1 item in the RecyclerView after I tap the download button.
I figured out how to wait for the RecyclerView to load. You can wait for a view that is inside the layout of item itself, such as a TextView:
app.WaitForElement(x => x.Marked("name_textView"), "Timed out waiting for items to load", TimeSpan.FromSeconds(3));

Select Item in NSCollectionView on mouseDown, not mouseUp?

I'd like to make it so my NSCollectionView's selection behavior matches the icon-view in Finder. Finder will select and highlight elements when the mouse button is clicked down, but NSCollectionView's built in behavior appears to use mouse up to trigger a selection.
Is there a way to make NSCollectionView act like Finder in this regard?
Per pfandtrade's comment above, it looks like the highlight state of an NSCollectionViewItem will be changed before that item is selected.
mouseDown = NSCollectionViewItem's highlightState is set to forSelection
mouseUp = NSCOllectionViewItem's highlightState is set to none, but isSelected property is then set to true.
I added the following to my NSCollectionViewItem subclass:
override var highlightState: NSCollectionViewItemHighlightState{
didSet{
if self.highlightState == .forSelection{
self.showSelectedHighlight() //my stylization function
}
}
}

How to create a swipe animation in blackberry cascades QML

I have a listview which has a customlist component and this component has two view inside (swipeleftview and swiperightview). I have implemented the swipe handler that shows these views correctly based on swipe left and right. Currently on my swipe gesture I have hidden the other view, ie while swiping left I hide the right view and show the left view and vice versa. Now instead of hiding I need them to animate like while swiping left the swipeleftview should animate to left and at the same time swiperightview should animate to its current position and vice versa. I have checked out some animations described in cookbook but cant seem to make it work properly. Below is a code structure of my listview and its item that I created
ListView {
id: contactListView
dataModel: contactsData
listItemComponents: [
ListItemComponent {
id: homeListComponent
type: "item"
CustomListItemHomePage { //some code to display items }
}]
}
CustomListItemHomePage is a container that has swipeleft and swiperight views

A strange symptom about mvvmlight listbox SelectedIndex focused color after transition of pages

I have a question about Mvvmlight binding Listbox SelectedIndex.
The full source code can be downloaded here.
Here is my precondition:
[TestModel]
string Title;
string Description;
[TestViewModel]
ObservableCollection<TestModel> TestList;
[xaml binding]
<ListBox ItemSource="{Binding TestList}"
SelectedIndex="{Binding SelectedIndex Mode=TwoWay}">
.....
<i:EventTrigger EventName="SelectionChanged">
.....
</i:EventTrigger>.....
Here is my OnSelectionChanged code:
private void OnSelectionChanged(TestModel test)
{
int index = SelectedIndex;
Debug.WriteLine("[SelectionChanged] +++, index={0}", index);
// If selected index is -1 (no selection) do nothing
if (-1 == SelectedIndex)
return;
Debug.WriteLine("[SelectionChanged] selected item={0}", test.Title);
// Reset selected index to -1 (no selection)
SelectedIndex = -1;
Debug.WriteLine("[SelectionChanged] ---, index={0}", index);
}
I have a sample to have MainPage.xaml and TestPage.xaml.
MainPage: This page has a button, click the button will navigate to TestPage
TestPage: This page has a listbox and binding to ViewModel
When I run this sample, tap button to TestPage, and try to tap any item of Listbox, I can see the item has no focused color (because I reset SelectedIndex to -1).
Here comes the question, when I back to MainPage, then again tap button to TestPage, you will see tapping any item of Listbox will cause focused color on every item, it's strange.
Hope anyone can help me to see if any problem on my sample.
Thanks.
I got a workaround from somebody below:
Change:
<i:EventTrigger EventName="SelectionChanged">
To:
<i:EventTrigger EventName="Tap">
It really works as what I expected.
Tap can allow user to tap repeated ListItem, also "reset SelectedIndex = -1" can make selected item without highlight color.

scrolling a UIScrollView on the click of a button

I would like to know if it is possible for me to scroll a UIScrollView on the click of a UIButton, and if so, would someone be able to tell me how to.
I am currently using the below code to see if in the scrollview more content is there to its left and if it is there, display an image which would tell the users that there is more content if they scroll to the left.
I would like to implement a functionality where I add a UIButton instead of the image and when more content is available on the left and when the user clicks the button, the scrollview would scroll to its left.
Code:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView1
{
if (scrollView1.contentOffset.x == scrollView1.contentSize.width - scrollView1.frame.size.width)
{
// reached the right
self.imageView.hidden = YES;
}
else
{
self.imageView.hidden = NO;
}
}
It would be great if someone could help me out on this.
You can easily make the scrollview scroll by using the scrollRectToVisible:animated: of UIScrollView. You just have to enter the rectangle where you want it to scroll and use YES for animated. For instance:
[yourScrollView scrollRectToVisible:CGRectMake(10,10,100,100) animated:YES];
You could also try setContentOffset, just like this:
[yourScrollView setContentOffset: CGPointMake(0, 0) animated: YES]
Simply call this method in the IBAction of your button. Replace the yourScrollView with the UIScrollView instance you created yourself. This will automatically scroll your scrollView to the left.
Hope this may help.

Resources