I am looking at this issue which is effecting me:
https://github.com/xamarin/Xamarin.Forms/issues/3087
It mentions that this is a problem with a
Steps to Reproduce
Just use a switch on a non app compat application
But what's a "non app compat application"
Also does anyone know any more about the history of this problem. Is it just for Switch or for many other elements. Which version of Android is causing it? Looks like a big problem for anyone using an Android custom renderer.
Here's an explanation from the docs:
Originally, the default Xamarin.Forms Android project used an older style of control renderering that was common prior to Android 5.0. Applications built using the template have FormsApplicationActivity as the base class of their main activity.
The sample project referenced in the github issue inherits from FormsApplicationActivity (non AppCompat):
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
The docs also mention that modern projects use AppCompat:
Xamarin.Forms Android projects now use FormsAppCompatActivity as the base class of their main activity. This class uses AppCompat features provided by Android to implement Material Design themes.
Related
We've begun evaluating Xamarin for a up and coming project involving both iOS and Android, with the overriding intention to produce a single UI layer (and some share code, obviously) (I'm also new to C#)
TL;DR
I've begun exploring Xamarin on iOS. I started with the Phoneword example and it worked well enough.
The first issue I found was running the code on the iPhone X, which I was able to solve by using MainPage.On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); in the platform App class
While testing this, I noticed some issues with the ListView not scrolling properly (the core issue was actually with the platform padding).
I then used (MainPage as Xamarin.Forms.NavigationPage).On<iOS>().EnableTranslucentNavigationBar(); to enable translucent navigation bars (as we're targeting iOS 11+) and now everything appears under the navigation bar.
This is easily fixed in xCode and after some research I've found that I need to be using UIKit.UIViewController.EdgesForExtendedLayout Property, the immediate problem I'm facing is, the only "snippets" of code I can find are from the View is displayed under status bar in iOS 7 and EdgesForExtendedLayout doesn't help forum post.
Issue at hand...
The example solution snippets posted seem to be making use of a platform (iOS) specific solution. The problem is, I want to keep using the "cross-platform" code in the "platform" project and simply provide some custom configuration for the iOS platform which can apply these states.
I understand it could be possible to use a renderer, but this seems to counter-interactive, as I'd need one for both iOS and Android, where the platform page is doing just fine as it.
I understand that I could setup a DependencyService, but this seems annoying to have to include a specific "configuration" service just to solve this issue for iOS
I was hoping it might be possible to setup a iOS Page which would "override" some of the functionality of the platform page and would allow me to make use of things like viewDidLoad so I can apply the iOS specific configurations on a page by pages bases, so we could keep the platform page as it, but when running under iOS, it would provide me access to iOS life cycle of the actual view...
I've been trying to search the documentation and tutorials and haven't yet come across anything which would seem to do this or something similar (not to say there isn't one, but I'm just not finding it).
I already have a solution which consist of Xamarin.iOS and UWP. We have multiple views (Pages) in both platforms. We are using MvvmCross, so we have a common code (PCL) which consists of Viewmodels, business logic etc. Also, we have separate views (Pages) for both Xamarin.iOS and UWP.
Now I want to add Xamarin.Forms support for native pages of both projects so that we have same views for both Xamarin.iOS and UWP. We need the support of navigation (from Native to Xamarin.Forms & vice versa). I am navigating through MvvmCross navigation service.
For instance,
I have FirstFormView in Xamarin.Forms project.
I have SecondFormView in Native project (can be Xamarin.iOS or UWP).
I have ThirdFormView in Xamarin.Froms project.
I have navigated to FirstFormView (which is staring page of my application)
Now I want to go to SecondFormView (which is in native project).
And from SecondFormView I need to go to ThirdFormView which is again in Xamarin.Forms
Is it possible to do it MvvmCross? If yes, then what steps should we follow to achieve our desired goal.
Thanks in advance.
Regards,
This is possible through the Forms presenters. Take a look at the playground: https://github.com/MvvmCross/MvvmCross/tree/develop/TestProjects/Playground/Playground.Forms.Droid
Here the views are all Forms, but 1 or 2 are in Native. By using the same solution you should be able to do this.
You already have MvvmCross in your PCL project, just need to add Xamarin Form pages (XAML) for every page in platform specific project (iOS, UWP). And custom renderers for every platform.
For example:
//in xamarin forms pcl project
namespace XFormProject
{
public class MyXFormPage : ContentPage project
{
}
}
// in ios project
namespace XFormProjecy.iOS
{
[assembly:ExportRenderer(typeof(XFormProject.MyXFormPage), typeof(XFormProject.iOS.MyXFormPageIOS))]
public class MyXFormPageIOS : PageRenderer // in iOS
{
// your ios native page code goes here.
}
}
Read more about Custom Rederers
Hope this helps :)
I have a Xamarin.Forms application that I would like to enable as a text and/or URL share target. I've done this in a Windows UWP app by handling OnShareTargetActivated, but I don't see an equivalent in Xamarin.Forms. I am willing to use compiler directives if needed; I would prefer that to doing iOS/Android/Windows specific things in the corresponding projects themselves. Right now all my code is in the Xamarin.Forms project and I'd like to keep it that way.
Unfortunately Android and Ios do not have a similar share event so there is no equivalent event in xamarin forms.
I am using Shared Project for my cross platform mobile application and want to use Custom renderer in my app for native support. Is there any way i can use Custom renderer in my app.
There is no difference in-between using custom renders in a PCL or Shared Project as seen here. You still have a project per platform. That doesn't change. The real advantage is that you can use ifdefs when compared to PCLs.
here is all the information you'll need in regards to implementing custom renders. And here is an example of a custom renderer for an Entry.
For Xamarin shared base project we have to set local in xmlns below format
xmlns:local="clr-namespace:Sampleforms"
For Xamarin PCL base project we have to set local in xmlns below format
xmlns:local="clr-namespace:Sampleforms;assembly=Sampleforms"
Reming everything will be same as what do for custom render.
I have four libraries all in all, a PCL and three platform-specific class libraries for Android, iOS and Win Phone. I have a base class for a custom Xamarin.Forms view in the PCL and renderers for it in the platform-specific libraries.
In the project where I use the libraries, the OnElementChanged() function of the iOS renderer is never called. I have tested on Android thus far, and there it works and the view gets rendered. Why might this be?
To complicate things, I have used the libraries in another project, where they work seamlessly on all three platforms.
I can provide more information if needed.
As there is not much info...
Make sure ExportRendererAttribute is set for the renderer
Make sure only one renderer available for the Control