I'd like to use the same images in multiple device apps in Xamarin.
I have a PCL core library and have started using MVVMCross.
What's the best approach to accomplish this? Can I embed them as a resource in the Core library and access it in my Andriod/iOs project, or is it better to use add as link?
You can in theory embed these as binary resources in the PCL project and can then access them as byte[] via GetResourceStream and from there can then get them decoded in your UI projects. This would require some work to setup and would make it impossible to use the images in the xib editor, in the android XML, etc
More easily, you can also share these image files using 'Add as link' and then allow each individual platform to optimize and package the files - each platform is good at this - eg Android with its different dpi drawable folders and IOS with its 2x image packaging. This technique also works well with the xib and XML designers.
However, in practice I generally find I don't share these image files between projects - instead on most commercial projects, the PhotoShop guys insist on giving me icons, dividers, and other chrome images which are unique to each platform.
Related
For Xamarin.Android it's simple as it only involves 1 platform (and resources are stored in Projectname.Android/Resources/mipmap-{hdpi|mdpi|xhdpi...}). For Xamarin.Forms on the other hand the code refers to single resources/images and as far as they work on different platforms (the same code and the same resources), I can't find a way to provide resources for different resolutions to be automatically picked up based on the screen size/dpi?
Is there a way to achieve that in common Xamarin.Forms project or shall I go and handle it in platform-specific projects' (Android, iOS) code?
The best thing so far is this plugin Resizetizer. You can have all your images in shared project and all images are generated during build time for all platforms (don't worry about the build time, it is similar to incremental build). This approach will also be in .NET Maui which will be launched with .NET 6.
There is also super nice video which really helpful!
As Xamarin.Forms does not seem to support loading image resources from a mipmap folder at this time,you could put different dpi images into the drawable folder like (Resources/drawable--{hdpi|mdpi|xhdpi...}) like mipmap.Then it will pick up the image based on the screen size/dpi automatically.
I'm creating a RN app that is meant to be some kind of wrapper. It should have multiple targets (like in Xcode) and all its content (images, text, etc.) should be target dependent. Unfortunately, I cannot find any useful informations about how to achieve this without opening Xcode or Android Studio project and create those targets manually (like here). Is there any other solutions for this?
I was still struggling with described problem but I finally found a solution. It's not easy, needs writing a bit of boilerplate code and looks more like a workaround but I hope it will help someone in the future. What I did is I have completed my wrapper app with the resources for one of my targets so I can have visual effect. In the project's root directory I've created a folder with subfolders for each target. Inside each I have put files (images, source code files, other assets) that are target-dependent. Then I've created bash script that takes one argument - target's name. Based on it, it replaces all the target-dependent files from target's subfolder to the original file's destination in the project structure. In this proces all meta-data informations are also replaced so after firing .sh file I can build the app and upload it to both stores. It's really time consuming to create all these apps separately and publish them and it's maybe not the best solution, but at least it works!
On android, you can edit build.gradle files, java or properties, without having to launch Android Studio (which simply uses Gradle)
You can build different type flavours by only changing app/build.gradle
On iOS, that's another story. Project file (.pbxproj) is a mess,and other Workspace/Scheme files are not easy to read or script. So XCode is the way to Go.
I tried to have dynamic target & Info.plist, there are tools to script that like PlistBuddy
in the end, I saw there are many ways to launch a React Native app for developpers. Some prefer the command line, and only VSCode.
Others want to play with native IDE.
By the way, native IDEs are VERY useful.
e.g. : you want to fine-tune your application performance, using XCode view hierarchy debugger or android Studio Layout Inspector (and be sure you don't use to many views), or use any other performance tools these IDEs offer...
In the end, I used react-native-config along with multiple almost similar configs (Info.plist < target < Scheme for each), here's a post giving an overview of the setup.
I have a Xamarin Forms project supporting iOS / Droid.
The solution also contains the PCL and two other external references.
I'm asked to create different language versions, meaning one .ipa / .apk per language.
In every project (language) only some files have to be changed (images / props on helper classes)
Is it possible to reuse the same files from my original project and just add the different files?
I have seen it working on Windows Phone but can't get it on XF.
Any ideas ?
P.S: I want to avoid copying 4 times each project.
Regards.
You should use resource file, it support images
https://developer.xamarin.com/guides/xamarin-forms/advanced/localization/
I'm starting to develop projects in Lazarus IDE, and I'm not adapted to the new platform. How can I import audio media, images, videos and other resources in the project and so use them (without the need to use a specific directory of the operating system).
Taking advantage of the same situation, it would be feasible to create a zip file type and import it into the project or create a package containing these resources.
NOTE: I want to use the images in a TImage object and define the resources imported into the picture property.
for images:
myImage.picture.LoadFromFile('img.bmp');
or
myImage.picture.LoadFromFile('folder1/img.bmp'); // not only .bmp is allowed
at the beggining you are in the same folder as the application is
about sounds:
the sound's format is required to be .wav
in youtube are some good tutorials
https://www.youtube.com/watch?v=SkhV7FuUpI4
good luck
We have an Xcode project that includes both Retina graphics for a NIB-based UI and a WebView UI. This project builds an app for the Mac.
The project uses two separate build phases to move these graphics into the final app. The first is the traditional Copy Bundle Resource which gets both the 1x and 2x graphics into the application package. The second is a Copy Files build phase which copies the web graphics into a separate Resources destination with a "graphics" subpath.
(This avoids some naming conflicts and lets the web designer use a familiar "graphics/whatever.png" path.)
When building this project, we get a Dependency Analysis Error that says:
Multi-representation image 'whatever#2x.png' cannot be processed by a
Copy Files build phase - try a Copy Resources build phase, or disable
COMBINE_HIDPI_IMAGES.
It's easy enough to turn off the Deployment Build Setting called "Combine High Resolution Artwork", but this affects the graphics used in the NIB-based UI as well as the ones in the WebView UI. With the option turned on, button.png and button#2x.png get combined into a button.tiff in the application package's Resource folder. Without it, the original names are used.
As far as I can tell, the application behaves normally, but since COMBINE_HIDPI_IMAGES is set on by default, I suspect there is some benefit to deploying the graphics as a single file (faster to load and cache, perhaps.)
Ideally, I'd like to only disable COMBINE_HIDPI_IMAGES during the Copy Files build phase. I can't figure out a way to do this, hopefully someone else here can...
Update 8/27/2012
For this particular application, the easiest way to fix the problem was to replace all HTML images with the 2x version. Since the tags specify a width and a height, the images are scaled down by 50% on a non-Retina device. The quality is fine and since they're being loaded from the local filesystem there's not perceivable performance impact.
Update 8/28/2012
Another approach we took was with naming conventions. Some HTML images are specified using CSS (with a media query selecting the Retina or non-Retina version.) To avoid problems with these images being combined into a single HiDPI image, we used whatever.png and whatever_retina.png.
The only way I can think to do it is a bit of a hack, but no one else has answered so as it should work for you.
I suggest you use an xcconfig file on your target (target.xcconfig) to specify the settings you want changed, then have build scripts before/after the phase which replace the current xcconfig with one of two versions (target-on.xcconfig, target-off.xcconfig). This should work, however Xcode may not update the xcconfig file until later (I'm not in a position to check at the moment), you'll have to check.
I'll leave it up to you to figure out the details. More details on (a less hackish variation) of this approach, and how to set it up, can be found at my blog.