IcoMoon colored icons on react-native-vector-icons plugin not working properly - react-native

I have created a font pack from Icomoon tool to be able to use it on my react-native app. Black & White icons seems to load just fine, but colored icons are broken and forced to be black & white while in the app.
I'm doing the following to add it, (I also added it manually on XCode inside Resources folder, it's everything linked there)
import { createIconSetFromIcoMoon } from 'react-native-vector-icons';
import icomoonConfig from './../selection.json';
const Icomoon = createIconSetFromIcoMoon(icomoonConfig, 'icomoon', 'icomoon.ttf');
const icomoon = {
'book': [30],
'book-color': [30],
'find': [30],
'find-color': [30],
'match': [30],
'match-color': [30],
'megaphone': [30],
'megaphone-color': [30]
}
const icomoonLoaded = new Promise((resolve, reject) => {
Promise.all(
Object.keys(icomoon).map(iconName =>
Icomoon.getImageSource(
iconName.replace(replaceSuffixPattern, ''),
icomoon[iconName][0],
icomoon[iconName][1]
)
),
).then(sources => {
Object.keys(icomoon)
.forEach((iconName, idx) => (
iconsMap[iconName] = sources[idx]
));
resolve(true);
});
});
export {
iconsMap,
icomoonLoaded
};
When I imported them in the page, the ones in color are loaded fine, although, it shows a "Multicolor" info next to each icon as if it was wrong to do or I have to handle it differently?
In the docs for vector-icons with icomoon, there's not much information about it.
Anyone has an idea on why this is happening? Thanks.

I'm having the same issue, It seems like your are only able to use a single color per icon when using icomoon + react-native-vector-icons. See this warning from the icomoon download page (press the "(i) Muticolor" text from your screenshot)
Font glyphs cannot have more than one color by default. Using CSS, IcoMoon stacks multiple glyphs on top of each other to implement multicolor glyphs. As a result, these glyphs take more than one character code and cannot have ligatures.
To avoid multicolor glyphs, re-import your SVG after changing all its colors to a single color.
As the message says, css is included to fix this issue but it can't be used in React native.
Your best bet is to either load it as an image or to create multiple icons as layer and in the code combine them on top of each other. Mimicking what the included style.css usally does

You can use the icons you get from Icomoon as SVG with multiple color.
React-Icomoon Repo
React-Icomoon with Multiple Color (Demo)

Related

Jetpack Compose Desktop – MaterialTheme.colors.background Not Working

Setting MaterialTheme.colors
I'm trying to make a very basic window in Jetpack Compose for Desktop (not mobile), but I'm having some difficulties with changing the colors of the window. I've looked at some tutorials and examples, but maybe I don't quite understand how color themes are correctly implemented.
The code that I wrote should create a window with a dark background, but the window when the program runs is white.
Please provide any insights you can as to what I am doing wrong.
Code (Kotlin)
import androidx.compose.desktop.*
import androidx.compose.material.*
import androidx.compose.ui.unit.*
fun main() = Window(
title = "Window",
resizable = false,
size = IntSize(1200, 800),
) {
MaterialTheme(colors = darkColors()) {
}
}
Window
Other Info
macOS Big Sur
IntelliJ 2021.2
Jetpack Compose 0.4.0
The MaterialTheme only provides colors for all views inside the container, it does not create or render the view.
Most Material components will use these colors as default values, but you can also use these colors in your views using, for example, MaterialTheme.colors.background.
You need to put some view inside, size it and apply some background color, for example:
MaterialTheme(colors = darkColors()) {
Box(Modifier.fillMaxSize().background(MaterialTheme.colors.background))
}
You can use Scaffold to see changes.
In your example:
...
MaterialTheme(colors = darkColors()) {
Scaffold {
// your content
}
}
...
You can read about it:
https://developer.android.com/jetpack/compose/layouts/material
or here:
https://metanit.com/kotlin/jetpack/4.11.php

since expo 34.0.0 update fonts doesn´t load anymore, do you know how can I fix it?

I have expo 30 proyect and the fonts ( fontello icons ) load succesful now 3 months later I reopen the proyect before update expo and fonts does´t load even if I create a new proyect the fonts does´t
(I have already changed the import from
import { Font } from 'expo';
to
import * as Font from 'expo-font';)
here's a snack with the problem https://snack.expo.io/#emmalv/bold-banana
it's curious that in expo-cli when I run the same code and print the state of loading first return false and before true and inmediately show red screen saying that font has not been loaded through Font.loadAsync
I've tried wirtting everything in the app class instead of loading the fonts from another file and the behavior is the same
other thing I've tried is like the new documentation says, use expoAssetId
const expoAssetId = require("assets/fonts/custom-icon-font.ttf");
const Icon = createIconSetFromFontello(fontelloConfig, 'FontName', expoAssetId);
but I get another error
C.replace is not a function. (In 'C.replace(/\.(otf|ttf)$/,'')', 'C.replace' is undefined)
Expected Behavior
the icons load and show correctly
Actual behavior
when load throw an exception 'fontFamily "../assets/fonts/sowaicons" is not a system font and has not been loaded through Font.loadAsync.' and show a square instead of the icon
Enviroment
Windows 10
sdkVersion: 35.0.0,
expo: ^35.0.0",
expo-font: ~7.0.0
I created working example:
https://snack.expo.io/#djalik/custom-fonts
change CustomIcon code:
import { createIconSetFromFontello } from '#expo/vector-icons';
import fontelloConfig from '../assets/fonts/config.json';
// const ttf = require("../assets/fonts/sowaicons.ttf");
// import myfont from "../assets/fonts/sowaicons.ttf";
const Icon = createIconSetFromFontello(fontelloConfig, 'sowaicons');
and replace this.state.setState... to this.setState

How to create a simple animation effect

Is there a code sample available that illustrates how to use a 2D transform (such as rotate and scale) with a JPG in a react-native application, perhaps with the code in the tutorial as a starting point?
If possible, it would be helpful to see code for two scenarios:
1) automatically apply a transform when the app is launched
2) apply a transform after different types of user gestures
At some point in the future it would be interesting to see how to create 3D transforms and animation effects.
Update: You can see the entire example in my sample app here: https://github.com/grgur/react-native-memory-game
Animation is now AnimationExperimental so we'll need to modify zvona's solution.
First, make sure RCTAnimationExperimental is a linked library
If not, then follow these steps:
Navigate to node_modules/react-native/Libraries/Animation/
Drag and drop RCTAnimationExperimental.xcodeproj to Libraries (should look like the image above)
Click on your project name (in the example above, my project name is Memory)
Switch to the Build Phases tab
Expand Libraries/RCTAnimationExperimental.xcodeproj/Products
Drag libRctAnimationExperimental.a to Link Binary With Libraries
Ok, the hardest part is now over. Head over to your JavaScript file. Animation is no longer part of the react-native package so we have to include it explicitly.
var React = require('react-native');
var AnimationExperimental = require('AnimationExperimental');
Alright, champ, you're ready to animate. Make sure you know what you're animating. The view you will be animating is referred to as node.
AnimationExperimental.startAnimation({
node: this.refs.image,
duration: 400,
easing: 'easeInQuad',
property: 'opacity',
toValue: 0.1,
});
And that's it!
At the moment of writing, available properties are: opacity, position, positionX, positionY, rotation, scaleXY
Currently, this is a bit more complex process and I'm planning to write a blog post about that. However, as a brief starter, I write something here.
First problem is that RCTAnimation / RCTAnimationManager is not present at all, if you've created your project with react-native init [ProjectName] (https://github.com/facebook/react-native/issues/226).
You need to add it in XCode from a plus sign in top left corner: "Add Files to [ProjectName]". Then you navigate to node_modules > Libraries > Animation > RCTAnimation.xcodeproj. After it's imported, you need to drag it under Libraries in your project.
Then you need to open tab Build Phases. There you have menu Link Binary With Libraries (x items). Drag from Products under RCTAnimation.xcodeproj file named libRCTAnimation.a to the menu.
Now, you can build your project to support animations. I'm not that familiar with XCode, so there could be a even more simple way of achieving this, but I got it sorted like this.
Second Problem is that not all the available (or planned) functionality is there. At least I ran through the jungle of trials and errors before I got anything on the screen.
Try e.g. this code at first to get fully proofed that animations are working:
var {
Animation,
AppRegistry,
StyleSheet,
Text,
View
} = React;
var styles = StyleSheet.create({
test: {
width: 400,
height: 400,
backgroundColor: 'blue',
opacity: 0
}
});
var AnimationTest = React.createClass({
componentDidMount () {
Animation.startAnimation(this.refs['this'], 400, 0, 'linear', {opacity: 1});
},
render () {
return (
<View ref='this' style={styles.test}>
<Text>Just an animation test</Text>
</View>
)
}
});
AppRegistry.registerComponent('AnimationTest', () => AnimationTest);
This should get you going. If you need any further assistance, please notify me.
If I ever succeed in writing a more complete instructions in a form of a blog article, I'll update it to this answer.
Check out the 2048 demo application for example usage of the RCTAnimation library:
https://github.com/facebook/react-native/tree/master/Examples/2048
It doesn't use any especially complex transforms, but does animate position, opacity, and scaleXY of various elements with code that looks like this:
Animation.startAnimation(this.refs['this'], 300, 0, 'easeInOutQuad', {scaleXY: [1, 1]});

Railscast 153 revised: setting a background image

I'm trying to generate a PDF following the instructions given in http://railscasts.com/episodes/153-pdfs-with-prawn-revised
I'm able to put a background image on a specific page by doing this:
image "#{Rails.root.to_s}/public/document_assets/1_cover.png", :at => [bounds.left - 30, bounds.top + 50], :fit => [#width, #height]
I also got an image to render on the background of multiple pages at once using:
repeat(2..3) { canvas { image("#{Rails.root.to_s}/public/document_assets/1_bg.png", :at => bounds.top_left, :fit => [#width, #height]) } }
but that renders the image on top of everything else on the page, so no text or other content is visible.
I can't seem to figure out how to set the background image property as described in the Prawn documentation. Does anyone know how to do this?
Thanks!
I figured out the problem. You can set the background option in the PDF class where the margins get set in the railscast example. My issue was that the image I was using was not the right size. When I sized it to 8.5x11" and 72px per inch, it worked.

Titanium: Tab's icon image not working

I am trying to change icons of my tab group's tab, but it doesn't show the image.
For iOS
I've used below code:
var win1 = Titanium.UI.createWindow
({
url:'Tab1.js'
});
var tab1 = Titanium.UI.createTab
({
icon:'footer_contactus_hover.png',
window:win1
});
// create controls tab and root window
var win2 = Titanium.UI.createWindow
({
url:'Tab2.js'
});
var tab2 = Titanium.UI.createTab
({
icon:'footer_search.png',
window:win2
});
I am having 4 tabs. Image's size is 81x51 . It shows me only blue rectangle instead of original image.
Also I've tried <property name="ti.android.fastdev" type="bool">false</property>
Whats wrong with the code ?
Assuming that your image does exist at the locations specified my first guess would be that your images are not created properly so that when the get masked all you see is a blue rectangle. I would suggest grabbing some other icon images from http://glyphish.com/ to see if it may be that your images are not created properly (I do not have any affiliation with that except I have used their icons in my projects and they are top-notch).
Also you may want to check out the Human Interface Guidelines as it sets forth specified sizes.
Solved by making images Transparent.
Also found : - Icon needs to be fileld with a color for visible pixels and transparent for the invisible part. The os will apply the blue glowing stuff, so if icon does not have transparent pixels you will only see a rectangle.