ToolbarItems do not look right in iOS - ios

I have a Xamarin.Forms app with FreshMvvm, and am trying to use secondary ToolbarItems. Here is a part of my PageModel code:
public override void Init(object initData)
{
CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "About LATICRETE", Command = AboutCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Call LATICRETE", Command = CallCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Email Technical Support", Command = EmailTechSupportCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
CurrentPage.ToolbarItems.Add(new ToolbarItem() { Text = "Visit LATICRETE Website", Command = VisitWebsiteCommand, Priority = 0, Order = ToolbarItemOrder.Secondary });
For Android, after pressing the hamburger button, the menu looks like I expect:
But at iPhone, it is quite different:
As you can see, there is no hamburger button, and all the ToolbarItems are placed horizontally next to each other, and as they do not fit withing the width of the screen, they overlap. I realize that this is the normal behavior for iOS, and yet it is not acceptable for me. Is there any way to fix it?

On iOS, the Secondary items menu appears below the navigation bar as a horizontal list.
if you want to acheve the effect like in Android,you could create a custom PageRenderer.
here is a sample,you could refer to it iOSSecondaryToolbarMenubar
the effect in Android :
the effect in ios (you could change the icon in your renderer):
1) the first page has the toolbar items:
2) all pages have the toolbar items:

Related

Jetpack navigation compose, bottom nav, make back button switch tabs?

I'm trying to use bottom navigation (ie, tabs) with Android Jetpack Compose and the Navigation Compose library. I have it set up with multiple back stacks, so that the state of each tab is preserved when you switch between them. However, if I change tabs by tapping one of them, the Android back button does not go back to the previous tab. Instead it navigates within that tab. How do I set it up to go back to previous tab?
Example scenario (I want to change behavior of last step).
I have two tabs, A and B.
Start in the A tab, on screen A1.
Push a new screen in that tab, called A2.
Tap the B tab to move to it, on its start screen B1.
Push a new screen in that tab, B2. So the tab stacks are now: A:[A1,A2], and B:[B1, B2]
Tap the A tab. I'm back in that stack, on screen A2. The state in that tab was preserved.
Press Android back button. It goes to A1. Instead I want it to go back to the B tab, screen B2.
MyAppBottomNavItem.all.forEach { item ->
BottomNavigationItem(
icon = { Icon(item.icon, contentDescription = null) },
label = {
Text(item.name, maxLines = 1, textAlign = TextAlign.Center,
overflow = TextOverflow.Visible, softWrap = false,
fontSize = 10.sp)
},
selected = currentDestination?.hierarchy?.any { it.route == item.route } == true,
alwaysShowLabel = true,
onClick = {
nav.navigate(item.route) {
popUpTo(nav.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
}

How to render a UIButton in Xamarin.iOS

How do I render a UIButton in Xamarin.iOS? See the current Code for the full list.
This is the code I'm using to create and add the button to the Xamarin.Forms.Platform.iOS.CellTableViewCell cell. I cannot get the button to display anything.
With the use of a Foundation.NSMutableAttributedString, it shows a cut-off section of text in the top left corner, regardless of anything I try (alignments, insets, bounds, various constraints, etc). I'm currently trying things from Xamarin.Forms.Platform.iOS.Renderers.ButtonRenderer, but still can't get anything to display at all, no text, no button, or its outline.
If you could fork the repo and fix it or post the solution here, I would be very grateful.
protected override void SetUpContentView()
{
var insets = new UIEdgeInsets(SVConstants.Cell.PADDING.Top.ToNFloat(), SVConstants.Cell.PADDING.Left.ToNFloat(), SVConstants.Cell.PADDING.Bottom.ToNFloat(), SVConstants.Cell.PADDING.Right.ToNFloat());
_Button = new UIButton(UIButtonType.RoundedRect)
{
AutoresizingMask = UIViewAutoresizing.All,
HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
VerticalAlignment = UIControlContentVerticalAlignment.Center,
ContentEdgeInsets = insets,
// TitleEdgeInsets = insets
};
DefaultFontSize = _Button.TitleLabel.ContentScaleFactor;
DefaultTextColor = _Button.TitleLabel.TextColor;
_Recognizer = new UILongPressGestureRecognizer(RunLong);
_Button.TouchUpInside += OnClick; // https://stackoverflow.com/a/51593238/9530917
_Button.AddGestureRecognizer(_Recognizer); // https://stackoverflow.com/a/6179591/9530917
ContentView.AddSubview(_Button);
_Button.CenterXAnchor.ConstraintEqualTo(ContentView.CenterXAnchor).Active = true;
_Button.CenterYAnchor.ConstraintEqualTo(ContentView.CenterYAnchor).Active = true;
_Button.WidthAnchor.ConstraintEqualTo(ContentView.WidthAnchor).Active = true;
_Button.HeightAnchor.ConstraintEqualTo(ContentView.HeightAnchor).Active = true;
UpdateConstraintsIfNeeded();
LayoutIfNeeded();
}
Found out that you can't subclass it. Any button added to the view must be native (UIButton) or custom rendered, such as Xamarin.Forms.Platform.iOS.ButtonRenderer; It doesn't show up otherwise.

LeftBarButtonItem with UISearchBar is not visible on iOS 11

The title is pretty self explanatory, on iOS 10.3 using a UIBarButtonItem with a custom view (in this case UIStackView) assigned to a LeftBarButtonItem of a NavigationBar is not visible on iOS 11. I haven't figure out why it is not showed but when I type something with the keyboard my logic of the TextChanged event works! So the UISearchView is there but it is not visible:
Here is some code (It is coded with C# but it is using Objective C methods.):
var width = NavigationController.NavigationBar.Frame.Width;
var height = NavigationController.NavigationBar.Frame.Height;
_searchBarContainer = new UIStackView(new CGRect(0, 0, width * 0.75, height))
{
Alignment = UIStackViewAlignment.Center,
Axis = UILayoutConstraintAxis.Horizontal,
Spacing = 3
};
_uiSearchBar = new UISearchBar
{
BackgroundColor = UIColor.Clear,
BarTintColor = UIColor.Clear,
BackgroundImage = new UIImage(),
Placeholder = Strings.Search
};
_uiSearchBar.SizeToFit();
if (_iOS11)
{
_uiSearchBar.HeightAnchor.ConstraintEqualTo(44).Active = true;
}
_searchbarButtonItem = new UIBarButtonItem(_searchBarContainer);
NavigationItem.SetLeftBarButtonItem(_searchbarButtonItem, true);
ParentViewController.NavigationItem.LeftBarButtonItem = NavigationItem.LeftBarButtonItem;
Using the same code on iOS 10 this works.
Please try out setting up constraints to size properly your _searchBarContainer before setting it as the left bar button item. From iOS11 navigations bars use auto layout. Make sure you only add the constraints if iOS 11 is present, I was having problems in iOS 9 navigation bars otherwise.
Also checkout this thread in the Dev forum where it's explained how the bar items are wrapped inside stack views, maybe also helps with your particular issue.

After android text keyboard hided custom keyboard displayed twice

In my activity class i use both custom keyboard and android soft text keyboard. Android text soft keyboard resizes activity layout. If I open custom keyboard while soft keyboard is opened, the last one hides and layout expands back. But I open custom keyboard right after call
InputMethodManager imm = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(view.WindowToken, 0);
Here view is view with custom keyboard.
And I face the problem when custom keyboard draws twice:
When android soft keyboard is hidden, but layout is not expanded back yet. In that case custom keyboard appears at the top half of the screen.
After layout is expanded back. In that case custom keyboard appears on the bottom half of the screen.
What i want to do is somehow avoid two keyboards simultaneous appearance.
In activity code i use only SoftInput.StateAlwaysHidden WindowSoftInputMode. SoftInput.AdjustPan is not convenient because in that case some views can be hidden by android keyboard.
After hours of internet search the answer has been found. Pspdfkit has great post.
And with small investigation it has been rewritten on C# in Oncreate method:
private View decorView;
private int lastVisibleDecorViewHeight = 0;
decorView = Window.DecorView;
decorView.ViewTreeObserver.GlobalLayout += (sender, args) =>
{
Rect windowVisibleDisplayFrame = new Rect();
decorView.GetWindowVisibleDisplayFrame(windowVisibleDisplayFrame);
int visibleDecorViewHeight = windowVisibleDisplayFrame.Height();
if (lastVisibleDecorViewHeight != 0)
{
if (lastVisibleDecorViewHeight > visibleDecorViewHeight)
{
OnSoftKeyboardShown();
}
else if (lastVisibleDecorViewHeight < visibleDecorViewHeight)
{
OnSoftKeyboardHidden();
if (!isAndroidSoftKeyboardShown && customKeyboardRequested)
{
Keyboard.RequestCustomKeyboard(requestedCustomKeyboardType);
customKeyboardRequested = false;
}
}
}
lastVisibleDecorViewHeight = visibleDecorViewHeight;
};
Hope this will help someone with similar problems.

Xamarin UITabbar multi bar items

I am using Xamarin Studio 6.0
I have created a TabBar and have added multi items to it, the items cover each others.
This is the code and screenshot:
var items = new UITabBarItem[10];
for (int i = 0; i < 10; i++)
{
var tabBarItem = new UITabBarItem("TAB ITEM"+i, null, i);
items[i] = tabBarItem;
}
TabLanguageBar.Items = items;
TabLanguageBar.ItemSpacing = 10;
TabLanguageBar.ItemSelected += (sender, e) =>
{
Console.WriteLine("tab bar button item slected");
};
That is the way a UITabBar works, you will need to either display a subset of them at one time or alter your UI design.
A tab bar displays all of its tabs onscreen at once, using the itemPositioning property to determine how to position items in the available space.
If you have more items than can fit in the available space, display only a subset of them and let the user select which tabs are displayed. The beginCustomizingItems: method displays an interface for selecting which tab bar items to display.
Ref: UITabBar

Resources