Skip to content

Commit

Permalink
- Upgrading RNVectorIcons
Browse files Browse the repository at this point in the history
- Font family lookup hot fix
  • Loading branch information
prscms committed Aug 21, 2018
1 parent bc7494e commit 27024e3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"babel-preset-react-native": "4.0.0",
"jest": "22.0.6",
"react-test-renderer": "16.2.0",
"prettier-pack": "0.0.4"
"prettier-pack": "0.0.7"
},
"jest": {
"preset": "react-native"
Expand Down
8 changes: 3 additions & 5 deletions js/RNShineButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ class RNShineButton extends PureComponent {
let shape;
if (this.props.shape && this.props.shape.props) {
let icon = this.props.shape.props;
let glyph = RNVectorHelper.Resolve(icon.family, icon.name);
let vectorIcon = RNVectorHelper.Resolve(icon.family, icon.name);

shape = Object.assign({}, icon, {
glyph: glyph,
size: this.props.size
});
shape = Object.assign({}, icon, vectorIcon);
shape = Object.assign({}, shape, { size: this.props.size });
} else {
shape = {
shape: this.props.shape
Expand Down
70 changes: 53 additions & 17 deletions js/RNVectorHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import EntypoGlyphMap from "react-native-vector-icons/glyphmaps/Entypo.json";
import EvilIconsGlyphMap from "react-native-vector-icons/glyphmaps/EvilIcons.json";
import FeatherGlyphMap from "react-native-vector-icons/glyphmaps/Feather.json";
Expand All @@ -11,91 +10,128 @@ import OcticonsGlyphMap from "react-native-vector-icons/glyphmaps/Octicons.json"
import SimpleLineIconsGlyphMap from "react-native-vector-icons/glyphmaps/SimpleLineIcons.json";
import ZocialGlyphMap from "react-native-vector-icons/glyphmaps/Zocial.json";

class RNVectorHelper {
import { Platform } from "react-native";

static Resolve (family, name) {
let glyph;
class RNVectorHelper {
static Resolve(family, name) {
let glyph, fontFamily;

switch (family) {
case "Entypo":
glyph = EntypoGlyphMap[name];
if (typeof glyph === 'number') {
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}
fontFamily = "Entypo";

return glyph
return { glyph: glyph, family: fontFamily };
case "EvilIcons":
glyph = EvilIconsGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}
fontFamily = "EvilIcons";

return glyph;
return { glyph: glyph, family: fontFamily };
case "Feather":
glyph = FeatherGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}
fontFamily = "Feather";

return glyph;
return { glyph: glyph, family: fontFamily };
case "FontAwesome":
glyph = FontAwesomeGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}
fontFamily = "FontAwesome";

return glyph;
return { glyph: glyph, family: fontFamily };
case "Foundation":
glyph = FoundationGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}

return glyph;
if (Platform.OS === "ios") {
fontFamily = "fontcustom";
} else {
fontFamily = "Foundation";
}

return { glyph: glyph, family: fontFamily };
case "Ionicons":
glyph = IoniconsGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}
fontFamily = "Ionicons";

return glyph;
return { glyph: glyph, family: fontFamily };
case "MaterialCommunityIcons":
glyph = MaterialCommunityIconsGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}

return glyph;
if (Platform.OS === "ios") {
fontFamily = "Material Design Icons";
} else {
fontFamily = "MaterialCommunityIcons";
}

return { glyph: glyph, family: fontFamily };
case "MaterialIcons":
glyph = MaterialIconsGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}

return glyph;
if (Platform.OS === "ios") {
fontFamily = "Material Icons";
} else {
fontFamily = "MaterialIcons";
}

return { glyph: glyph, family: fontFamily };
case "Octicons":
glyph = OcticonsGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}
fontFamily = "Octicons";

return glyph;
return { glyph: glyph, family: fontFamily };
case "SimpleLineIcons":
glyph = SimpleLineIconsGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}

return glyph;
if (Platform.OS === "ios") {
fontFamily = "simple-line-icons";
} else {
fontFamily = "SimpleLineIcons";
}

return { glyph: glyph, family: fontFamily };
case "Zocial":
glyph = ZocialGlyphMap[name];
if (typeof glyph === "number") {
glyph = String.fromCharCode(glyph);
}

return glyph;
if (Platform.OS === "ios") {
fontFamily = "zocial";
} else {
fontFamily = "Zocial";
}

return { glyph: glyph, family: fontFamily };
}
}
}

export default RNVectorHelper
export default RNVectorHelper;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-shine-button",
"version": "0.0.10",
"version": "0.0.11",
"description": "React Native Bridge for ChadCSong/ShineButton & imwcl/WCLShineButton",
"main": "js/RNShineButton.js",
"repository": {
Expand All @@ -16,10 +16,10 @@
],
"author": "Pranav Raj Singh Chauhan",
"dependencies": {
"react-native-vector-icons": "^4.6.0"
"react-native-vector-icons": "5.0.0"
},
"devDependencies": {
"prettier-pack": "0.0.6"
"prettier-pack": "0.0.7"
},
"license": "Apache License"
}

0 comments on commit 27024e3

Please sign in to comment.