Xamarin Forms - How to animate show/hide of item in StackLayout? - animation

I've got a Xamarin Forms cross-platform application (iOS and Android), and on one of the screens I want a list with details:
Heading 1
Detail 1
Detail 2
Detail 3
Heading 2
Detail 1
Heading 3
Detail 1
Detail 2
As you can see, the amount of detail under each heading is variable.
I want the page to display at first with just the headings:
Heading 1
Heading 2
Heading 3
And then when the user presses on a heading, the details for that particular heading appear. Pretty standard stuff.
I've tried several different ways to get this to work, the only path that seems open to me is to have a StackLayout where I define a bunch of labels:
new StackLayout
{
Orientation = StackOrientation.Vertical,
Children =
{
new Label { Text = "Heading 1" },
new Label { Text = " Detail 1\n Detail 2\n Detail 3", IsVisible = false },
new Label { Text = "Heading 2" },
new Label { Text = " Detail 1", IsVisible = false },
new Label { Text = "Heading 3" },
new Label { Text = " Detail 1\n Detail 2", IsVisible = false }
}
}
I then add a TapGestureRecognizer to the heading labels, and when tapped I toggle the value of IsVisible for the detail labels. It works!
The only thing I don't like, is that there is no transition. I click on the heading label and BAM the detail label appears (correctly pushing down all the following labels to make space for itself). I would like an animation so that when I click on the header, the space beneath the header "slowly" opens up to reveal the detail.
As I read about animations online, one possibility is to set the HeightRequest of the detail labels to zero (instead of hiding them with IsVisible=false) and then creating an animation that "slowly" changes the HeightRequest from zero to the actual height of the label. And that's where I run into a problem.
I can't figure out how to get Xamarin to tell me the height of my "details" label.
If I inspect the Height and HeightRequest properties of my details label right after creating it, they are both -1 (no big surprise there). If I inspect those same two properties when I click on the heading, they are still -1. The only way I've found to get the height of my detail label, is to set the detail label visible, call ForceLayout() on my stack layout, store the detail label height, and then set the detail label invisible again. The problem with that is that I sometimes see the detail label flash visible for an instant while I do this.
What's the best/recommended way to accomplish my desired UI?

You can use the Animation API.
Read the blog about it - Creating Animations with Xamarin.Forms.
In particular for your scenario you can use the FadeTo method to animate the Opacity property of a Visual Element.
Eg :
await image.FadeTo (1, 4000);
For more information, see Animation.
In your case my suggested approach would be for showing a label, to set opacity of label to 0, then make it visible, and then use FadeTo to make the opacity to 1.
Use the opposite to hide the label, set opacity 0 via FadeTo, then set IsVisible to false.

If I understand right your problem the only thing you need is to avoid the flash on the label, if this is the case then you can set the Opacity to 0, in this way the label will not be visible until you set again the opacity to 1.

I can suggest you to make a custom XF control (to use as item DataTemplate) as follow:
2 vertical parts:
The header part (A) (when you click on it it will show the second part)
The second part is a 'Listview' control (B) that is empty at the beginning
When you click on (A):
it will show (B)
It will start to populate (B) with your details elements
The trick in my mind is to implement a method that populate the listview (B) item by item (getting them from your viewmodel) with some delay (a few milliseconds) between each insertion and maybe a 'fadeTo' effect too in the same time.
You can see here what I mean (see the "Fade" section):
Insert / fade list item effect sample in HTML
You can improve your template as you want, by embedding the two parts into a 'border' for instance, to make a graphical separation...
Tell me if it's unclear, all you need is time :)
And maybe if you are ready, you can try to make native controls / animations...

Related

Scroll one page to the right in Cypress

How could I scroll one page to the right in Cypress?
E.g. I have a horizontally scrollable area. The area contains elements a, b and if I scroll to the right a and b get destroyed, while c and d get added.
My attempt is to find out the width of the scrollable view and then scroll that amount to the right. But the width does not get retrieved before the scrollTo gets called.
Here is what I am trying to do:
const width = cy.getCy("scroll-viewport").invoke("width");
cy.getCy("scroll-viewport").scrollTo(width, 0);
Your code sample has some mystery about it, for example what is cy.getCy().
I can show you how to do it with standard code, and you can adapt from there.
Assuming scroll-viewport is a selector for the scroll container (the owner of the scroll bar)
cy.get("scroll-viewport").then($scrollContainer => {
const width = $scrollContainer[0].offsetWidth;
$scrollContainer[0].scrollTo(width, 0);
})
Note $scrollContainer[0].scrollWidth gives you the total width after scrolling, in case you need that.

Override the Autolayout center values of UIButton in a Subview # viewDidLayoutSubviews

I use Autolayout for a fairly complex Menu and really need it. All Buttons, UIViews etc. of my Menu are in a separate UIView called "menuSubview".
If the user presses a button the whole "menuSubview" shifts to another position to reveal other parts of the menu. Sometimes the buttons in the menuSubview move as well. I always save the "Menu State" (with Userdefaults in the get-set variable "lastMenu") and have a function to set the alphas and centers according to the saved "Menu State".
I tried calling the "openLastMenu" function in viewDidAppear, viewDidLayoutSubview - all the "viewDid" functions of the ViewController. The "menuSubview" center and alphas of the buttons always behave as expected... but the centers of the buttons simply won't - no matter what "viewDid" I call the function in.
(the code is a lot more complex - I boiled it down to debug and state my point)
override func viewDidAppear(animated: Bool) {
if lastMenu != nil {openLastMenu()}
}
func openLastMenu(){
menuSubview.center.x = view.center.x //works
menuSubview.center.y = view.center.y + 200 //works
button1.center.x = view.center.x - 50 //why you no behave???
button2.center.x = view.center.x + 50 //why you no behave???
button3.alpha = 0 //works
button4.alpha = 0 //works
}
For debugging I even made a button Subclass to fetch the "center" values with a "didSet" if they change. Seems like after taking the correct values they change once more to their Autolayout-Position.
...oh and ignoring the constraints with "translatesAutoresizingMaskIntoConstraints" on the buttons always fucks up the whole menu. I'm starting to get crazy here :)
If you position views using autolayout, any changes to the frame, like what you do here with the center property, will be ignored.
What you need to do is identify the constraints that are you need to change to move the views in the desired position. Example:
You want to move button1 50 points to the left of view.center. Assuming view is the superview of menuSubview, you would
1) deactivate the the constraint responsible for button1's horizontal placement. How you do this mainly depends on whether you created the constraints in code or Interface Builder. The latter will require you to create outlets for some of the constraints.
2) create a new constraint between button1's centerX anchor and view's centerX anchor with a constant of -50, like so (iOS 9 code)
button1.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor, constant: -50.0).active = true

How do I center a textbox inside a panel in visual studio?

When I set the textbox's anchor to top,bottom,left,right the textbox still stays on the top. I don't understand, this seems to work for labels and buttons. I kinda need this anchor property for it to adapt well to a form resize.
I'm sorry if I'm missing something incredibly obvious.
If I understand your question, you want a single line textbox to appear centered vertically and horizontally in your form. Still without showing more than one line. In this case you could set just the Anchor Left and Right property to have you textbox centered horizontally on the form, but for the vertical position you need to work with code adjusting the Iop property of the textbox in the Resize event of the form
For example, after the call to InitializeCompoment of your form you could add the following code to center your textbox (C# but easily convertible to VB.NET)
textBox1.Left = 10;
textBox1.Width = yourForm.ClientSize.Width - 20;
textBox1.Top = (yourForm.ClientSize.Height / 2) - yourForm.Height / 2;
textBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
and then add the event handler for the resize event of your form where you could call again the vertical repositioning of the textbox
protected void yourForm_Resize(object sender, EventArgs e)
{
textBox1.Top = (this.ClientSize.Height / 2) - textBox1.Height / 2;
}

AmCharts. Aligning balloons

I've spent a lot of time finding the solution, but i can't see any property in AmChatrts documentation that can align balloons not vertically. Actually, I just want to see all balloons, but not in one column. Can anybody help me?
There is currently no way to make the balloons stack in any different way than in once column. However, there are a few alternatives you can consider.
1) Displaying just one balloon.
To do that, set oneBalloonOnly to true:
var chart = AmCharts.makeChart("chartdiv",{
...
"chartCursor": {
"oneBalloonOnly": true
}
});
This will make the cursor display just one balloon of the closest graph.
2) Disable balloons and use a legend instead.
To disable balloons, simply set [valueBalloonsEnabled][3] in chart cursor's settings to false.
var chart = AmCharts.makeChart("chartdiv",{
...
"chartCursor": {
"valueBalloonsEnabled": false
},
"legend": {}
});
The legend will show relative value next to each graph title when you hover over the chart.
3) Consolidate values from multiple graphs into a single balloon.
To do that, use graph's balloonText property. It lets you reference to any field in data, so you can make it display values from any graph.
Here's a good example of the above.
Here's a good demo on how to do that.

Is it possible to set the alignment of kendo datepicker's dropdown calendar in kendo grid with respect to the textbox

When the datatype is Date, the kendo grid uses a kendo datepicker with dropdown calendar for the column.
The datepicker's dropdown calendar usually aligns itself flush with the left edge of the input box. If there isn't room for that, it is moved to the left, but not quite enough. This presents a problem when the rightmost column in the grid is a Date, and the grid is occupying 100% of the width available on the screen: the Saturday column in the dropdown calendar gets "cut off". See pic attached.
Is it possible to tell the calendar dropdown (for a particular column) to align itself flush with the right edge of the text input?
I know that bug. Your datepicker animation container is hidden under right scrollbar. If you set body overflow to hidden, you will not have a scrollbars and calendar will fit and touch right border of screen, like in this example: http://dojo.telerik.com/UCOhA
However if you can't turn off the body scrollbars you need to set calendar position manually dirty way like this:
$("#piker").kendoDatePicker({
open: function(e) {
//setTimeout to let kendo make k-animation-container element at first open
setTimeout(function(){
var animationContainer = $("#" + e.sender.element.attr("id") + "_dateview").parent();
var left = e.sender.element.offset().left + e.sender.element.closest('.k-datepicker').width() - animationContainer.width();
animationContainer.css('left', left);
});
},
//turnoff the animation to avoid strange visual effects
animation: {
open: {
duration: 0
}
}
});
Running example: http://dojo.telerik.com/Imiqa/2

Resources