Nativescript and FontAwesome - android

I am trying to use icon font FontAwesome in Nativescript application, which is possible according to this article https://www.nativescript.org/blog/mobile-app-best-practices---use-font-instead-of-image-to-show-an-icon
I did everything that is described in that article:
Added .ttf in app/fonts
Added class in app.css
.fa{
font-family: "FontAwesome";
}
Used it in XML like so
text="" class="fa"
But result is rather disappointing:
I also tried the "\uf230" syntax, but that renders as plain text.
What am I doing wrong?

Could be a few things. Does it work on iOS? As your CSS definition is iOS compatible, not Android as Android needs the actual filename (without extension) whereas iOS needs the font name. So I have this to be xplatform-ready (the file is 'fontawesome-webfont.ttf'):
.fa {
font-family: 'FontAwesome', fontawesome-webfont;
}
The \f005 syntax is OK (<Label class="fa" [text]="'\uf005'"></Label>), but I'm using the splendid nativescript-ngx-fonticon plugin (there's also a non-Angular one) to be able to do this instead:
<Label class="fa" [text]="'fa-shopping-basket' | fonticon"></Label>

To make it work, you must make sure that the "fonts" directory is inside the "app" folder and that the following files exist:
font-awesome.eot
font-awesome.ttf
I opted to adopt this font as the default of my application, so I do not have to worry about where I'm going to use it and how much to enter the right class, everything is getting very good and the result is perfect.
In CSS, you only have to define a selector according to your interest for the source to be used, so just use the directive:
page {
font-family: 'FontAwesome'
}
Then where you want an icon, just use an html entity that represents it as it searches the site: http://fontawesome.io/icons/
See images:
You can see this video where I was based to start. It corrects in the video the extension used to be attentive.

Related

Atrributes Selection is NOT working on Android browsers 4.x

I have a problem with attributes (PrestaShop 1.6)
http://www.zapateriamiqueca.es/ropita/20-leotardos-condor.html
If you click on Choose Size (Talla): from any browser (Chromme, Firefox...) but on Android 4.x o 5.x it works right, but... if you click on Choose Size: from android 4.x browser default it opens the options to select from then closes it straight away.
I followed these instructions:
Open up product.tpl inside your themes folder and look for:
<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="form-control attribute_select no-print">
2- Comment out form-control after class so it looks like:
<select name="{$groupName}" id="group_{$id_attribute_group|intval}" class="attribute_select no-print">
3- Then to add your global.css file inside your {your_theme}/css Add the following to make it look go again (The numbers after group vary per website, so take a look which group number is being used for you attribute selector):
select#group_3.attribute_select {width: 60%!important;}
select#group_1.attribute_select {width: 60%!important;}
I managed to get up to modifying the product.tpl but I'm not sure where to copy the code lines in point 3, in order to maintain the attribute selection style.
I also don't know where to look for my group number. I really would appreciate your help.
Thank you for yout time! ;-)
If you look at your source code you'll find:
<select name="group_3" id="group_3" class="form-control attribute_select no-print">
So your groupName id for this value is group_3 as in the example.
You need to edit this file /themes/Calisto/css/global.css and add this line at the end before saving:
select#group_3.attribute_select {width: 60%!important;}
I'm not saying it will work to solve your problem, but that's what your instructions say.

react-native android fontFamily does not take effect

Question 1:
I add a fontFamily to index.android.js's welcome style, but it takes no effect. Does fontFamily actually work on android?
welcome:{
fontSize:20,
fontFamily:'roboto-thin',
textAlign:'center',
margin:10}
Question 2:
if fontFamily works on android, is there a way to load custom font from assets? Or is this some feature to be implemented by react-native?
For Android:
Custom fonts were added with 0.16.0-rc. So you need to have 0.16.0-rc version first and after that you can just download any fonts from the web.
Put your font files in projectfolder/android/app/src/main/assets/fonts/font_name.ttf
Remember to recompile which is: react-native run-android
And then you can use fontFamily: 'font_name' in your style.
Also note the following restrictions for custom Android fonts in react-native:
fonts must be placed in android/app/src/main/assets/fonts
only .ttf files are supported
The name of the file has to match the fontFamily exactly. For instance, if fontFamily is 'Source Sans Pro',
the file must be called Source Sans Pro.ttf (and NOT SourceSansPro.ttf). Any suffixes as mentioned in the following paragraph are automatically removed from the file.
When the font is in bold and/or italic, it must use on the following suffixes:
_bold (e.g. Source Sans Pro_bold.ttf)
_italic
_bold_italic
Hello this issue waist for me more than two days with "El+Messiri" font "https://fonts.google.com/specimen/El+Messiri"
i was doing every think write :
Put your font files in
projectfolder/android/app/src/main/assets/fonts/ElMessiri-Regular.ttf
Remember to recompile which is: react-native run-android And then
you can use fontFamily: 'ElMessiri-Regular' in your style.
but the fault was that am using fontWeight : 'bold' after fontFamily: 'ElMessiri-Regular' and the fontWeight was overiding the fontFamily because "El+Messiri" font has his own fontFamily bold wich is "ElMessiri-Bold"
I believe the following is a cleaner alternative to the methods already explained here:
Put all your fonts in you React-Native project directory
./assets/fonts/
Add the following line in your package.json
"rnpm": {
"assets": ["./assets/fonts"]
}
finally run in the terminal from your project directory
$ react-native link
to use it declare this way in your styles
fontFamily: 'your-font-name without extension'
If your font is Raleway-Bold.ttf then,
fontFamily: 'Raleway-Bold'
Source https://medium.com/#danielskripnik/how-to-add-and-remove-custom-fonts-in-react-native-b2830084b0e4
This feature has yet to be implemented. See the relevant issue on github here.
It seems like custom font was added, check out this commit:
https://github.com/facebook/react-native/commit/bfeaa6a4f531cfc18c097bc9ffb6a8dbe3ddc702
For those facing problems with iOS only - which sometimes does not recognize the fontFamily name correctly:
The only solution that solved my problem was to log all the fonts to find out correct naming
(make sure you do the steps below only after adding the assets/fonts and running the react-native link):
Anyway, to log them, open the appName.xcworkspace file with xcode and then edit AppDelegate.m putting this lines at the end of the didFinishLaunchingWithOptions method (and before the return statement):
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
So, when you run the app (from xcode) it outputs something like this:
This way, I can use the fontFamily Barow-Light or Zapfino inside my react-native styles
Hope it helped!
I had an incredibly hard time with this, even after following all advice I found.
What worked for me: ensure the font file is named using only lowercase letters and underscores. Re-link. Done.
A lot of hair pulling has been done over this yet it isn't mentioned anywhere as far as I can see.

Can't use relative paths in object tags in Cordova/Phonegap?

I noticed that I can't use relative paths in my Cordova project when referencing them in object tags. For example, this works on the browser but not in Phonegap:
<object id="pause" type="image/svg+xml" data="img/icons/pause.svg" class="icon clickable hidden"></object>
However, this functions perfectly fine in both Phonegap and the browser:
<img id="pause" src="img/icons/pause.svg">
Using a remote path also works in Cordova, but everything falls apart when I use a local/relative one. Here's what Android spits back:
<img src="file:///android_asset/webkit/android-weberror.png" align="top">
<h2>Webpage not available</h2>
<p>The webpage at file:///android_asset/www/img/logo.svg could not be loaded because:</p>
<!-- The net::ERR_FILE_NOT_FOUND is replaced by a localized error string -->
<p>net::ERR_FILE_NOT_FOUND</p>
Unfortunately, I can't use a remote location (since that won't let me execute the onclick and onmousedown events inside the SVGs). Also, avoiding <object> tags altogether is not an option, since I need to execute and change some of the code inside the objects (like changing the fill color).
Is this a bug? If not, what can I do to get my code to work?
A jacky workaround to this is reading the file manually using Javascript and putting the contents directly into the data attribute so that it reads <object data="data:image/svg+xml;utf8,[FILECONTENTS]"></object>. It's not elegant, but it works fine.

Using Cordova, is there a way to reference native icons?

I'm using Cordova 3.5 to build an app which contains a menu with pretty standard items in the list (home, contacts, etc.), and I want to use the native menu icons whenever possible. I believe those icons are already on the device as part of the OS, but I don't know if Cordova gives me a way to reference them.
I suppose I'd need to write a Javascript function to choose the right file name based on the platform, e.g.:
// this is pseudocode
var icon = '';
if (platform === 'android') {
icon = 'some/path/home.png';
} else {
icon = 'other/path/icon.home.png';
// or maybe a function such as the following exists:
// icon = cordova.getNativeIcon('icon.home.png');
}
$('.selector').css('background-image', icon);
Alternatively, I may be able to make do by referencing the files in CSS, e.g.:
.android .home-icon {
background-image: url('some/path/home.png');
}
.ios .home-icon {
background-image: url('other/path/icon.home.png');
}
So, how do folks handle this sort of thing in Cordova? Is there a function I can use to access native icons? Are folks just copying them into their projects? What's the best practice?
If you're working with Cordova, then you'll be working inside a web view provided by the host OS and you won't have direct access to any artwork. I've found that using icon fonts and CSS "themes" to work well enough, but that approach will replicate artwork already provided. There's extra work involved with theming for iOS 6 vs iOS 7 or 8, for example, but it's not as bad as it sounds.
IBM does have an article on partitioning your view between native and web controls, but it sounds a bit cumbersome. More details here: https://www.ibm.com/developerworks/community/blogs/worklight/entry/ios_combining_native_and_web_controls_in_cordova_based_applications

Using Date Spinner in flex mobile application

I am unable to use DateSpinner component in my flex mobile application. I am only interest to print date but not time. How can I achieve this in my flex mobile project. Platform is Flash Builder 4.6.
<s:HGroup verticalAlign="middle">
<s:SpinnerListContainer>
<s:DateSpinner id="dt" />
</s:SpinnerListContainer>
</s:HGroup>
The above code gives following error.
TypeError: Error #1009: Cannot access a property or method of a null object reference. DateSpinner.as:1290
In the example code for the DateSpinner control, they are not wrapping it in a SpinnerListContainer. So perhaps that's your problem. Have you tried the DateSpinner by itself?
It appears to me that the SpinnerListContainer is intended to be used with a SpinnerList control. And that SpinnerList is for more generic lists, while DateSpinner is a stand alone component used specifically for dates/times.
The given code doesn't work when displayMode property is set to "date" only.
<s:DateSpinner id="ds"
selectedDate="{new Date(2010, 11, 15)}"
minDate="{new Date(2000, 0, 1)}"
maxDate="{new Date(2200, 11, 31)}"
minuteStepSize="5" displayMode="date" />
when I use <s:DateSpinner id="dt" displayMode="dateAndTime" /> its works fine but it do not works when I set displayMode="date"
even the simplest form to dataspinner gives error, like you use
<s:DateSpinner id="ds" />
i've the same problem. After debugging the as-code i found a problem with determine the textsize. So i look at my console output i found this warning: This component requires that the embedded font be declared with embedAsCFF=false.
Thereafter i configured my Font-Style:
#font-face {
src: url("assets/Sintony-Regular.ttf");
fontFamily: Sintony-Regular;
advancedAntiAliasing: true;
embedAsCFF: false;
embed-as-cff: flase;
font-lookup: embeddedCFF;
fontWeight: normal;
}
s|DateSpinner {
font-family: Sintony-Regular;
}
Now my DateSpinner works. But many other components gives the warning: This component requires that the embedded font be declared with embedAsCFF=true. It's not a fully solution, but a beginning. Mybe i have to use different font-face declarations.
Hope it works for you, too

Categories

Resources