Xamarin Shell windows full screen but show status bar - xamarin

How i can create with xamarin shell (android and ios) the Google Map effect (show app in full screen but not hide the status bar). Thx.
For Android i found:
In OnCreate method
Window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
But I still need to change the color of the icons?
No solution for iOS yet!

For Android:
1.Change the style.xml
You can add the code into the Android styles.xml. This can make the status bar transparent.
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
2.Adding method in MainActivity.cs.
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Kitkat)
{
Window.AddFlags(WindowManagerFlags.TranslucentStatus);
Window.AddFlags(WindowManagerFlags.TranslucentNavigation);
}
LoadApplication(new App());
For ios
You can refer to this article .
For more details about this question:
Xamarin Forms Android transparent status bar

Related

How to get UIView size in a Xamarin Forms custom renderer

I created a custom view renderer in Xamarin Forms and would like to know the size of the view so that I can add subviews with absolute positioning.
protected override void OnElementChanged(ElementChangedEventArgs<MyView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
if (Control == null)
{
var uiView = new UIView
{
BackgroundColor = UIColor.SystemPinkColor
};
SetNativeControl(uiView);
// How to get uiView width and height in absolute numbers?
}
}
}
When I check uiView.Frame, I'm getting 0 for width and height.
In PCL, MyView is displayed as a child of a Grid element.
Sorry for can not getting the size of View from OnElementChanged method , because this method is the same as ViewDidLoad method . The frame of View hasn't been calculated in this stage.
We can get width and height from Draw method , this stage viewcontroller will begin to draw view on screen according to the size of frame .Therefore we can definitely get the size now .
UIView uIView;
public override void Draw(CGRect rect)
{
base.Draw(rect);
Console.WriteLine("------------x" + uIView.Frame.Size.Width);
Console.WriteLine("------------x" + Control.Frame.Size.Width);
Console.WriteLine("------------x" + Control.Bounds.Size.Width);
}
Or other methods whose lifecycle is after OnElementChanged .Such as LayoutSubviews method:
UIView uIView;
public override void LayoutSubviews()
{
base.LayoutSubviews();
Console.WriteLine("------------" + uIView.Frame.Size.Width);
Console.WriteLine("------------" + Control.Frame.Size.Width);
Console.WriteLine("------------" + Control.Bounds.Size.Width);
}
Output :
2020-06-16 10:59:11.327982+0800 AppFormsTest.iOS[30355:821323] ------------375
2020-06-16 10:59:11.328271+0800 AppFormsTest.iOS[30355:821323] ------------375
2020-06-16 10:59:11.328497+0800 AppFormsTest.iOS[30355:821323] ------------375

Are React Native macOS menu bar apps possible?

Is there any way to currently create a React Native app that runs in the background within the macOS menu bar?
The question is not recent, but I found it searching for this topic and there is a recent relevant update: with the new desktop efforts from Microsoft, this is now feasible, although still tricky.
Credits to ospfranco for the great work.
The only way to do it is by editing your AppDelegate class and initialize the status button label and its popover content with the Root View content from the React Native application. It's also possible to customize its size, appearance and the button at the bar, but only in Swift code.
func applicationDidFinishLaunching(_ aNotification: Notification) {
let jsCodeLocation: URL
jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "tempomat", initialProperties: nil, launchOptions: nil)
let rootViewController = NSViewController()
rootViewController.view = rootView
popover = NSPopover()
popover.contentSize = NSSize(width: 700, height: 800)
popover.animates = true
popover.behavior = .transient
popover.contentViewController = rootViewController
statusBarItem = NSStatusBar.system.statusItem(withLength: CGFloat(60))
if let button = self.statusBarItem.button {
button.action = #selector(togglePopover(_:))
button.title = "Tempomat"
}
}
References:
React Native MacOS (Microsoft): https://github.com/microsoft/react-native-macos
Sample code: https://github.com/ospfranco/react-native-macos-menubar-template
Blog post: https://ospfranco.github.io/post/2020/05/23/how-to-make-a-react-native-menu-bar-app-for-mac-os/
As of now, the best way to do this is using the Electron platform.

SpriteKit Xcode level editor no touch events on custom button class (3d touch)

I am having trouble getting custom SKSpriteNode buttons to work with the xCode level editor on devices with 3d Touch.
I have a button subclass which is mostly based on the DemoBots sample from apple.
The basic code would be this
enum ButtonIdentifier: String {
case playButton
case pauseButton
}
/// Button responder delegate
protocol ButtonDelegate: class {
func pressed(button button: ButtonNode)
}
class ButtonNode: SKSpriteNode {
public weak var delegate: ButtonDelegate? {
return scene as? ButtonDelegate
}
var isHighlighted = false {
didSet {
// running skactions to colorise buttons and animate
}
}
var identifier: ButtonIdentifier!
/// Code init (when button is created in code)
/// e.g let playButton = ButtonNode(imageNamed: "ButtonImage", identifier: playButton)
init(imageNamed: String, identifier: ButtonIdentifier) {
self.identifier = identifier
let texture = SKTexture(imageNamed: imageNamed)
super.init(texture: texture, color: SKColor.clearColor(), size: texture.size())
name = identifier.rawValue
setup()
}
/// Level editor init (when button is created in level editor)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Ensure that the node has a supported button identifier as its name.
guard let nodeName = name, identifier = ButtonIdentifier(rawValue: nodeName) else {
fatalError("Unsupported button name found.")
}
self.identifier = identifier
setup()
}
private func setup() {
// zPosition
zPosition = 200
// Enable user interaction on the button node to detect tap and click events.
userInteractionEnabled = true
}
#if os(iOS)
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
isHighlighted = true
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
guard let scene = scene else { return }
for touch in touches {
let location = touch.locationInNode(scene)
let node = scene.nodeAtPoint(location)
if node === self || node.inParentHierarchy(self) {
runPressedAction()
} else {
isHighlighted = false
}
}
}
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
super.touchesCancelled(touches, withEvent: event)
isHighlighted = false
}
#endif
// MARK: - Pressed Action
private func runPressedAction() {
// SKAction that runs a press animation
delegate?.pressed(button: self)
}
}
If i create the button via the xCode level editor everything is working fine in the simulator or on my iPhone 6, however when using test flight my friend with a 6s Plus gets no touch input on the buttons, he cannot press them.
If I create the button all in code everything works, even on 3d touch devices.
Why is it not working with buttons from the level editor on 3d touch devices? I have been trying to look at apples demo bots sample to see if I missed some setting or something, but I cannot figure it out. (Demo bots buttons do work on my friends iPhone 6s plus)
I know that on 3d touch devices touchesMoved method gets called even though there are no changes in the x/y coordinates. However I don't think this causes my issues because when creating buttons in code everything is working as expected.
Is there some setting in the Xcode level editor I am missing to allow touches on 3d touch devices?
After days of frustration it turned out it was a iOS 9 bug. My friend was on iOS 9.2.x and after he updated to the latest iOS 9.3.x version everything is working, no code changes where required at all.

The NavigationBar Tint Color doesn't change when I press BackButton Xamarin.iOS

I have two ViewControllers in my app. I am using Xamarin.iOS. I want to navigate from VC1 to VC2 and change the background color of NavigationBar (BarTintColor) so different VCs should have different NavigationBarColors.
Code in VC1:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
//change the navigation bar controller
this.NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB (26f / 255f, 56f / 255f, 100f / 255f);
this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes()
{
ForegroundColor = UIColor.White
};
NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
}
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
this.NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB (26f / 255f, 56f / 255f, 100f / 255f);
}
Code in VC2:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
// change the back button
UIBarButtonItem newBackButton = new UIBarButtonItem("Prapa",UIBarButtonItemStyle.Plain, (sender,args) => NavigationController.PopViewController (true));
newBackButton.TintColor = UIColor.White;
NavigationItem.SetLeftBarButtonItem (newBackButton, false);
//change the title of the screen
NavigationItem.Title = "Horoskopi Ditor";
NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB(47f/255f,189f/255f, 184f/255f);
}
Now the problem is: I am able to change the color when I navigate form VC1 to VC2 but when I go back to VC1 the color doesn't change.
My guess is that I need to override some method than, when a screen appears to change the background color. In the VC1 I have override the ViewDidAppear but it gave me no result. Any Idea?
Hey did you try ViewWillAppear:
VC1:
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
if (NavigationController != null)
{
NavigationController.NavigationBar.BarTintColor = UIColor.FromRGB (26f / 255f, 56f / 255f, 100f / 255f);
}
}
With ViewDidAppear the view is already on Screen and ViewWillAppear its not on screen so you can change the Navbar.

WKWebView fallback to UIWebView in swift2?

In my SWIFT project, I use WKWebView for iOS 8 and fall back to UIWebView for iOS 7, using this line of code:
var webView: WKWebView?
#IBOutlet weak var containerView: UIWebView!
However, this is not allowed in SWIFT 2 in the new Xcode 7. What is the best alternative if I still want to support iOS 7?
I had the same problem. I added this dictionary to my info.plist. Now the WKWebView loads as expected.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Here's the example code for just the purpose.
var subWKView: UIView?
//on view load, initiate the WKWebView and fall back to UIWebView
override func loadView() {
if #available(iOS 8.0, *) {
//this is only allowed to be used in the func block
let webView: WKWebView!
webView = WKWebView()
//code for initiating WKWebView using addSubview
//reference to the WKWebView
self.subWKView = webView
} else {
//use UIView
}
}
//Use WKWebView in other func blocks
func useWKWebView() {
if #available(iOS 8.0, *) {
//cast to WKWebView
let webView = self.subWKView as! WKWebView
//use the webView
} else {
//use UIView
}
}

Resources