question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Views - View.Height += 1 does not have the expected behavior

See original GitHub issue

Before I use view.Height = view.Subviews.Count;, I had it in another way where I did view.Height += 1; I remove a lot of other views with Dim and Pos to other views, thinking maybe was circular reference or something. But no, the problem is just that line … view.Height += 1;

If you try this, it gets exponentially slower.

This is beacuse Dim.Combine. After 3 times, view.Height == {Dim.Combine(Dim.Combine(Dim.Combine(Dim.Absolute(0)+Dim.Absolute(1))+Dim.Absolute(1))+Dim.Absolute(1))}

Is this the expected behavior for this case ???

Maybe if it’s the same instance, combine should behave differently, because I think that view.Height += x is something very basic to have such a behavior.

public override void Setup ()
{
  var view = new View () { X = 0, Y = 0, Width = 20, Height = 0 };
  var field = new TextField () { X = 0, Y = Pos.Bottom (view), Width = 20 };
  
  field.KeyDown += (k) => {
	  if (k.KeyEvent.Key == Key.Enter) {
  
		  var label = new Label (field.Text) { X = 0, Y = view.Subviews.Count, Width = 20 };
		  
                  field.Text = "";
  
		  view.Add (label);
  
                  // works
		  view.Height = view.Subviews.Count;
                  
                  // don't try this at home
		  // view.Height += 1;
	  }
  };
  
  Win.Add (view);
  Win.Add (field);
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jmperriconecommented, May 8, 2021

@BDisp Sorry I couldn’t help you.

That is the way that Pos and Dim works, but why don’t do that?

view.Height = view.Bounds.Height + 1;

Yes, there are many ways to do this, but I think that operators should work as expected.

1reaction
jmperriconecommented, May 8, 2021

plus1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Height not updating on selected view · Issue #535
Expected Behavior ​​ When animateHeight={false} this problem does not occur. Every view's height is the same as the maximum view of any view,...
Read more >
Can't seem to make auto layout work right
So I have a Split View controller for my app. The Master View Controller does not want to layout correctly in different sizes,...
Read more >
ios10: viewDidLoad frame width/height not initialized ...
In Xcode 8, a fully constraint, non-misplaced view no longer saves out a frame to minimize diffs and support automatically update frames in...
Read more >
How to make a SwiftUI view to fill its container width and ...
We can use a frame modifier to make a view appear to be full width and height, but the result might not be...
Read more >
Understanding SwiftUI Layout Behaviors
When the behavior of a SwiftUI view is not the one you want you cannot alter its properties directly, as views themselves are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found