Skip to content

Commit bd289b3

Browse files
committed
- upgrading RNVectorIcons
- Font family lookup hot fix
1 parent f06a93a commit bd289b3

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

Example/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"test": "jest"
88
},
99
"dependencies": {
10-
"react": "16.4.1",
11-
"react-native": "0.56.0",
10+
"react": "16.3.1",
11+
"react-native": "0.55.3",
1212
"react-native-notification-banner": "../"
1313
},
1414
"devDependencies": {
15-
"babel-jest": "23.4.0",
16-
"babel-preset-react-native": "^5",
17-
"jest": "23.4.1",
18-
"react-test-renderer": "16.4.1"
15+
"babel-jest": "22.1.0",
16+
"babel-preset-react-native": "4.0.0",
17+
"jest": "22.1.4",
18+
"react-test-renderer": "16.2.0"
1919
},
2020
"jest": {
2121
"preset": "react-native"

android/src/main/java/ui/notificationbanner/RNNotificationBannerModule.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,42 +134,42 @@ public void onHide() {
134134
}
135135

136136

137-
@TargetApi(21)
137+
@TargetApi(21)
138138
private Drawable generateVectorIcon(ReadableMap icon) {
139139
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
140140
StrictMode.setThreadPolicy(policy);
141-
141+
142142
String family = icon.getString("family");
143143
String name = icon.getString("name");
144144
String glyph = icon.getString("glyph");
145145
String color = icon.getString("color");
146146
int size = icon.getInt("size");
147-
147+
148148
if (name != null && name.length() > 0 && name.contains(".")) {
149149
Resources resources = getReactApplicationContext().getResources();
150150
name = name.substring(0, name.lastIndexOf("."));
151-
151+
152152
final int resourceId = resources.getIdentifier(name, "drawable", getReactApplicationContext().getPackageName());
153153
return getReactApplicationContext().getDrawable(resourceId);
154-
}
155-
154+
}
155+
156156
float scale = getReactApplicationContext().getResources().getDisplayMetrics().density;
157157
String scaleSuffix = "@" + (scale == (int) scale ? Integer.toString((int) scale) : Float.toString(scale)) + "x";
158158
int fontSize = Math.round(size * scale);
159-
159+
160160
Typeface typeface = ReactFontManager.getInstance().getTypeface(family, 0, getReactApplicationContext().getAssets());
161161
Paint paint = new Paint();
162162
paint.setTypeface(typeface);
163163
paint.setColor(Color.parseColor(color));
164-
paint.setTextSize(size);
164+
paint.setTextSize(fontSize);
165165
paint.setAntiAlias(true);
166166
Rect textBounds = new Rect();
167167
paint.getTextBounds(glyph, 0, glyph.length(), textBounds);
168-
168+
169169
Bitmap bitmap = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888);
170170
Canvas canvas = new Canvas(bitmap);
171171
canvas.drawText(glyph, -textBounds.left, -textBounds.top, paint);
172-
172+
173173
return new BitmapDrawable(getReactApplicationContext().getResources(), bitmap);
174174
}
175175
}

js/RNNotificationBanner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class NotificationBanner extends PureComponent {
103103
if (props.icon && props.icon.props) {
104104
let icon = props.icon.props;
105105

106-
let glyph = RNVectorHelper.Resolve(icon.family, icon.name);
107-
props.icon = Object.assign({}, icon, { glyph: glyph });
106+
let vectorIcon = RNVectorHelper.Resolve(icon.family, icon.name);
107+
props.icon = Object.assign({}, icon, vectorIcon);
108108
}
109109
} else {
110110
props.icon = undefined;

js/RNVectorHelper.js

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,88 +10,126 @@ import OcticonsGlyphMap from "react-native-vector-icons/glyphmaps/Octicons.json"
1010
import SimpleLineIconsGlyphMap from "react-native-vector-icons/glyphmaps/SimpleLineIcons.json";
1111
import ZocialGlyphMap from "react-native-vector-icons/glyphmaps/Zocial.json";
1212

13+
import { Platform } from "react-native";
14+
1315
class RNVectorHelper {
1416
static Resolve(family, name) {
15-
let glyph;
17+
let glyph, fontFamily;
1618

1719
switch (family) {
1820
case "Entypo":
1921
glyph = EntypoGlyphMap[name];
2022
if (typeof glyph === "number") {
2123
glyph = String.fromCharCode(glyph);
2224
}
25+
fontFamily = "Entypo";
2326

24-
return glyph;
27+
return { glyph: glyph, family: fontFamily };
2528
case "EvilIcons":
2629
glyph = EvilIconsGlyphMap[name];
2730
if (typeof glyph === "number") {
2831
glyph = String.fromCharCode(glyph);
2932
}
33+
fontFamily = "EvilIcons";
3034

31-
return glyph;
35+
return { glyph: glyph, family: fontFamily };
3236
case "Feather":
3337
glyph = FeatherGlyphMap[name];
3438
if (typeof glyph === "number") {
3539
glyph = String.fromCharCode(glyph);
3640
}
41+
fontFamily = "Feather";
3742

38-
return glyph;
43+
return { glyph: glyph, family: fontFamily };
3944
case "FontAwesome":
4045
glyph = FontAwesomeGlyphMap[name];
4146
if (typeof glyph === "number") {
4247
glyph = String.fromCharCode(glyph);
4348
}
49+
fontFamily = "FontAwesome";
4450

45-
return glyph;
51+
return { glyph: glyph, family: fontFamily };
4652
case "Foundation":
4753
glyph = FoundationGlyphMap[name];
4854
if (typeof glyph === "number") {
4955
glyph = String.fromCharCode(glyph);
5056
}
5157

52-
return glyph;
58+
if (Platform.OS === "ios") {
59+
fontFamily = "fontcustom";
60+
} else {
61+
fontFamily = "Foundation";
62+
}
63+
64+
return { glyph: glyph, family: fontFamily };
5365
case "Ionicons":
5466
glyph = IoniconsGlyphMap[name];
5567
if (typeof glyph === "number") {
5668
glyph = String.fromCharCode(glyph);
5769
}
70+
fontFamily = "Ionicons";
5871

59-
return glyph;
72+
return { glyph: glyph, family: fontFamily };
6073
case "MaterialCommunityIcons":
6174
glyph = MaterialCommunityIconsGlyphMap[name];
6275
if (typeof glyph === "number") {
6376
glyph = String.fromCharCode(glyph);
6477
}
6578

66-
return glyph;
79+
if (Platform.OS === "ios") {
80+
fontFamily = "Material Design Icons";
81+
} else {
82+
fontFamily = "MaterialCommunityIcons";
83+
}
84+
85+
return { glyph: glyph, family: fontFamily };
6786
case "MaterialIcons":
6887
glyph = MaterialIconsGlyphMap[name];
6988
if (typeof glyph === "number") {
7089
glyph = String.fromCharCode(glyph);
7190
}
7291

73-
return glyph;
92+
if (Platform.OS === "ios") {
93+
fontFamily = "Material Icons";
94+
} else {
95+
fontFamily = "MaterialIcons";
96+
}
97+
98+
return { glyph: glyph, family: fontFamily };
7499
case "Octicons":
75100
glyph = OcticonsGlyphMap[name];
76101
if (typeof glyph === "number") {
77102
glyph = String.fromCharCode(glyph);
78103
}
104+
fontFamily = "Octicons";
79105

80-
return glyph;
106+
return { glyph: glyph, family: fontFamily };
81107
case "SimpleLineIcons":
82108
glyph = SimpleLineIconsGlyphMap[name];
83109
if (typeof glyph === "number") {
84110
glyph = String.fromCharCode(glyph);
85111
}
86112

87-
return glyph;
113+
if (Platform.OS === "ios") {
114+
fontFamily = "simple-line-icons";
115+
} else {
116+
fontFamily = "SimpleLineIcons";
117+
}
118+
119+
return { glyph: glyph, family: fontFamily };
88120
case "Zocial":
89121
glyph = ZocialGlyphMap[name];
90122
if (typeof glyph === "number") {
91123
glyph = String.fromCharCode(glyph);
92124
}
93125

94-
return glyph;
126+
if (Platform.OS === "ios") {
127+
fontFamily = "zocial";
128+
} else {
129+
fontFamily = "Zocial";
130+
}
131+
132+
return { glyph: glyph, family: fontFamily };
95133
}
96134
}
97135
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "react-native-notification-banner",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "ReactNative: Native Notification Banner",
5-
"main": "RNNotificationBanner.js",
5+
"main": "js/RNNotificationBanner.js",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/prscX/react-native-notification-banner.git"

0 commit comments

Comments
 (0)