My setup is:
I'm changing my view controllers by calling .transition(to: targetViewController) on the SnackbarController.
The problem I have is that my view controllers have the wrong height.
I've debugged some bounds:
// Screen's bounds
print(Screen.bounds)
// The SnackbarController's view's bounds
print(toolbarController?.rootViewController.view.bounds as! CGRect)
// The bounds of my view controller's view
print((toolbarController?.rootViewController as! AppSnackbarController).rootViewController.view.bounds)
The output was:
(0.0, 0.0, 768.0, 1024.0)
(0.0, 0.0, 768.0, 955.0)
(0.0, 0.0, 768.0, 1162.0) // This should be 955, right?
And it even becomes more weird: If change my view controller using .transition, the new view controller's height increases by 138 everytime. (It's 138 on all devices)
So if I change my view controller, it outputs:
(0.0, 0.0, 768.0, 1024.0)
(0.0, 0.0, 768.0, 955.0)
(0.0, 0.0, 768.0, 1300.0)
And if I change it again, it outputs:
(0.0, 0.0, 768.0, 1024.0)
(0.0, 0.0, 768.0, 955.0)
(0.0, 0.0, 768.0, 1438.0)
Maybe you can take a look...
Thanks!
When I comment out (RootController.swift : 129)
viewController.view.frame = rootViewController.view.frame
the SnackbarController's view doesn't get larger when changing view controllers. But it's still too large.
I will take a look :)
Is the issue that your views are behind the TabBarController ? If so, this is not actually a Material issue, but iOS in general. You need to set the edges of the view controller. Set in your rootViewController this property:
edgesForExtendedLayout = []
The issue is, that the rootViewController of my SnackbarController has always the wrong height. And the height gets increased by 138 every time I change the rootViewController using .transition()
I understand that. The frame doesn't get increased by any factor, rather it is made the same as the previous that is being transitioned from.
viewController.view.frame = rootViewController.view.frame
If you can share a sample that replicates this, that would be great. You are placing this inside a TabBarController, which does alter the size of UIViewControllers that are within it. Now I am not blaming that, but it is the only item that stands our right away. The RootController manages all navigation controller types (ToolbarController, MenuController, PageTabBarController, SnackbarController, etc... ) So I would suspect that the issue would manifest in all those too if there was an increase being set within the RootController.
This is where a sample project that replicates the issue would be very helpful.
I'll make one! :)
:) Thank you!
Okay, this is becoming strange... But maybe you do know what happens here:
I'm adding an ActivityIndicator as the Toolbar's rightView like this:
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .white)
let activityIndicatorContainer = UIView(frame: CGRect())
toolbar.rightViews = [activityIndicatorContainer]
activityIndicatorContainer.autoresizesSubviews = true
activityIndicatorContainer.addSubview(activityIndicator)
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
activityIndicatorContainer.addConstraint(NSLayoutConstraint(item: self.activityIndicator, attribute: .centerX, relatedBy: .equal, toItem: activityIndicatorContainer, attribute: .centerX, multiplier: 1, constant: 0))
activityIndicatorContainer.addConstraint(NSLayoutConstraint(item: self.activityIndicator, attribute: .centerY, relatedBy: .equal, toItem: activityIndicatorContainer, attribute: .centerY, multiplier: 1, constant: 0))
activityIndicator.startAnimating()
When I remove that part, we can completely forget that 138 thing, because it doesn't happen without that. (But I really want to know what happens there and how to add a vertical centered ActivityIndicator to a Toolbar)
But the view stills seems to be too high. I'm setting a tableView's background view like this (should be v- and h-centered):
let messageLabel = UILabel(frame: CGRect(x: 0, y: 0, width: self.tableView.bounds.size.width, height: self.tableView.bounds.size.height))
messageLabel.text = message!
messageLabel.textColor = Color.black
messageLabel.numberOfLines = 0;
messageLabel.textAlignment = .center;
messageLabel.font = UIFont(name: "TrebuchetMS", size: 15)
messageLabel.sizeToFit()
self.tableView.backgroundView = messageLabel;
self.tableView.separatorStyle = .none;
This is NavigationDrawerController > ToolbarController > SnackbarController > MyTableViewController:

And this is NavigationDrawerController > ToolbarController > PageTabbarController > MyTableViewController

And here is an example project. See AppDelegate.swift, line 41
I will take a look tomorrow :)
Looking at this now :)
Very nice, thank you!
So it all works :) I don't think you were showing the snackbar. Add this: animate(snackbar: .visible) to the AppSnackbarController class
The Snackbar is hidden by default.
The snackbar is not the problem. The problem is the snackbarController laying out its subviews (see the images above)
The first "Hello" should be centered, too, but it isn't. It's an UILabel as a TableView's backgroundView. And the TableView is inside a SnackbarController. If I put the TableView into another Controller, let's say a PageTabBarController (image #2), it is centered.
Fixed the issue :) Will make a release momentarily.
Please update to Material 2.3.21 :) It should be aligning correctly now. Thanks for catching this issue.
Wow, nice! Thank You! :-)
I will try this soon...
Yes, it works! Thanks! :-)
Most helpful comment
I will take a look :)