Skip to content

Commit e6b3ba8

Browse files
committed
WIP
1 parent a5928e3 commit e6b3ba8

16 files changed

+362
-198
lines changed

.editorconfig

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
# http://editorconfig.org
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
25
root = true
36

47
[*]
8+
59
indent_style = space
610
indent_size = 2
11+
712
end_of_line = lf
813
charset = utf-8
914
trim_trailing_whitespace = true

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pbxproj -text
2+
# specific for windows script files
3+
*.bat text eol=crlf

.gitignore

+55-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
1-
# Logs
2-
*.log
3-
4-
# Runtime data
5-
tmp
6-
.fontcustom-manifest.json
7-
build
8-
dist
9-
10-
# Dependency directory
11-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
12-
node_modules
13-
bower_components
1+
# OSX
2+
#
3+
.DS_Store
144

155
# Xcode
16-
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
1716
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
1824

19-
.DS_Store
25+
# Android/IJ
26+
#
27+
.classpath
28+
.cxx
29+
.gradle
30+
.idea
31+
.project
32+
.settings
33+
local.properties
34+
android.iml
35+
36+
# node.js
37+
#
38+
node_modules/
39+
npm-debug.log
40+
yarn-debug.log
41+
yarn-error.log
42+
43+
# BUCK
44+
buck-out/
45+
\.buckd/
46+
android/app/libs
47+
android/keystores/debug.keystore
2048

2149
# Yarn
2250
.pnp.*
@@ -26,3 +54,15 @@ xcuserdata
2654
!.yarn/releases
2755
!.yarn/sdks
2856
!.yarn/versions
57+
58+
# Turborepo
59+
.turbo/
60+
61+
# generated by bob
62+
lib/
63+
64+
# Runtime data
65+
tmp
66+
.fontcustom-manifest.json
67+
build
68+
dist

MIGRATION.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
* deprecated flow types
44
* Native typescript support
55
* Removed old react-vector-icons compatibility
6+
* Same support policy as react-native current + 2 (start with 0.73)
7+
* We should try and make the font packages not care about react native versions

android/build.gradle

+96-34
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,116 @@
11
buildscript {
2-
ext.safeExtGet = {prop, fallback ->
3-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
4-
}
5-
repositories {
6-
google()
7-
gradlePluginPortal()
8-
}
9-
dependencies {
10-
classpath("com.android.tools.build:gradle:7.0.4")
11-
}
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
7+
dependencies {
8+
classpath "com.android.tools.build:gradle:7.2.1"
9+
}
10+
11+
// ext.safeExtGet = {prop, fallback ->
12+
// rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
13+
// }
1214
}
1315

1416
def isNewArchitectureEnabled() {
15-
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
17+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
1618
}
1719

18-
apply plugin: 'com.android.library'
20+
apply plugin: "com.android.library"
21+
1922
if (isNewArchitectureEnabled()) {
20-
apply plugin: 'com.facebook.react'
23+
apply plugin: "com.facebook.react"
24+
}
25+
26+
def getExtOrDefault(name) {
27+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["VectorIcons_" + name]
28+
}
29+
30+
def getExtOrIntegerDefault(name) {
31+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["VectorIcons_" + name]).toInteger()
32+
}
33+
34+
def supportsNamespace() {
35+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
36+
def major = parsed[0].toInteger()
37+
def minor = parsed[1].toInteger()
38+
39+
// Namespace support was added in 7.3.0
40+
return (major == 7 && minor >= 3) || major >= 8
2141
}
2242

2343
android {
24-
namespace = "com.oblador.vectoricons"
25-
compileSdkVersion safeExtGet('compileSdkVersion', 31)
44+
if (supportsNamespace()) {
45+
namespace "com.oblador.vectoricons"
2646

27-
defaultConfig {
28-
minSdkVersion safeExtGet('minSdkVersion', 21)
29-
targetSdkVersion safeExtGet('targetSdkVersion', 31)
30-
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
31-
}
3247
sourceSets {
33-
main {
34-
if (isNewArchitectureEnabled()) {
35-
java.srcDirs += ['src/newarch']
36-
} else {
37-
java.srcDirs += ['src/oldarch']
38-
}
39-
}
48+
main {
49+
manifest.srcFile "src/main/AndroidManifestNew.xml"
50+
}
4051
}
52+
}
53+
54+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
55+
56+
defaultConfig {
57+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
58+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
59+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
60+
61+
}
62+
63+
buildFeatures {
64+
buildConfig true
65+
}
66+
67+
buildTypes {
68+
release {
69+
minifyEnabled false
70+
}
71+
}
72+
73+
lintOptions {
74+
disable "GradleCompatible"
75+
}
76+
77+
compileOptions {
78+
sourceCompatibility JavaVersion.VERSION_1_8
79+
targetCompatibility JavaVersion.VERSION_1_8
80+
}
81+
82+
sourceSets {
83+
main {
84+
if (isNewArchitectureEnabled()) {
85+
java.srcDirs += [
86+
'src/newarch',
87+
// This is needed to build Kotlin project with NewArch enabled
88+
"${project.buildDir}/generated/source/codegen/java"
89+
]
90+
} else {
91+
java.srcDirs += ['src/oldarch']
92+
}
93+
}
94+
}
4195
}
4296

4397
repositories {
44-
maven {
45-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
46-
url "$projectDir/../node_modules/react-native/android"
47-
}
48-
mavenCentral()
49-
google()
98+
mavenCentral()
99+
google()
50100
}
51101

102+
52103
dependencies {
53-
implementation 'com.facebook.react:react-native:+'
104+
// For < 0.71, this will be from the local maven repo
105+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
106+
//noinspection GradleDynamicVersion
107+
implementation "com.facebook.react:react-native:+"
108+
}
109+
110+
if (isNewArchitectureEnabled()) {
111+
react {
112+
jsRootDir = file("../src/")
113+
libraryName = "VectorIcons"
114+
codegenJavaPackageName = "com.oblador.vectoricons"
115+
}
54116
}

android/gradle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
VectorIcons_kotlinVersion=1.7.0
2+
VectorIcons_minSdkVersion=21
3+
VectorIcons_targetSdkVersion=31
4+
VectorIcons_compileSdkVersion=31
5+
VectorIcons_ndkversion=21.4.7075529

android/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.oblador.vectoricons">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.oblador.vectoricons">
23
</manifest>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.oblador.vectoricons;
2+
3+
import androidx.annotation.Nullable;
4+
5+
import com.facebook.react.bridge.ReactApplicationContext;
6+
import com.facebook.react.bridge.ReactMethod;
7+
8+
import com.facebook.react.views.text.ReactFontManager;
9+
10+
import android.content.Context;
11+
import android.graphics.Paint;
12+
import android.graphics.Canvas;
13+
import android.graphics.Typeface;
14+
import android.graphics.Rect;
15+
import android.graphics.Bitmap;
16+
import android.graphics.Bitmap.CompressFormat;
17+
import android.util.Log;
18+
19+
import java.io.File;
20+
import java.io.FileOutputStream;
21+
import java.io.IOException;
22+
import java.io.FileNotFoundException;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
public class VectorIconsModule extends VectorIconsSpec {
27+
public static final String NAME = "VectorIcons";
28+
29+
VectorIconsModule(ReactApplicationContext context) {
30+
super(context);
31+
}
32+
33+
@Override
34+
@NonNull
35+
public String getName() {
36+
return NAME;
37+
}
38+
39+
private static final Map<String, Typeface> sTypefaceCache = new HashMap<String, Typeface>();
40+
41+
@ReactMethod // FIXME: From template but this might be wrong
42+
public static String getImageForFont(String fontFamily, String glyph, Integer fontSize, Integer color, Context context) throws java.io.IOException, FileNotFoundException {
43+
File cacheFolder = context.getCacheDir();
44+
String cacheFolderPath = cacheFolder.getAbsolutePath() + "/";
45+
46+
float scale = context.getResources().getDisplayMetrics().density;
47+
String scaleSuffix = "@" + (scale == (int) scale ? Integer.toString((int) scale) : Float.toString(scale)) + "x";
48+
int size = Math.round(fontSize*scale);
49+
String cacheKey = fontFamily + ":" + glyph + ":" + color;
50+
String hash = Integer.toString(cacheKey.hashCode(), 32);
51+
String cacheFilePath = cacheFolderPath + hash + "_" + Integer.toString(fontSize) + scaleSuffix + ".png";
52+
String cacheFileUrl = "file://" + cacheFilePath;
53+
File cacheFile = new File(cacheFilePath);
54+
55+
if(cacheFile.exists()) {
56+
return cacheFileUrl;
57+
}
58+
59+
FileOutputStream fos = null;
60+
Typeface typeface = ReactFontManager.getInstance().getTypeface(fontFamily, 0, context.getAssets());
61+
Paint paint = new Paint();
62+
paint.setTypeface(typeface);
63+
paint.setColor(color);
64+
paint.setTextSize(size);
65+
paint.setAntiAlias(true);
66+
Rect textBounds = new Rect();
67+
paint.getTextBounds(glyph, 0, glyph.length(), textBounds);
68+
69+
int offsetX = 0;
70+
int offsetY = size - (int) paint.getFontMetrics().bottom;
71+
72+
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
73+
Canvas canvas = new Canvas(bitmap);
74+
canvas.drawText(glyph, offsetX, offsetY, paint);
75+
76+
try {
77+
fos = new FileOutputStream(cacheFile);
78+
bitmap.compress(CompressFormat.PNG, 100, fos);
79+
fos.flush();
80+
fos.close();
81+
fos = null;
82+
83+
return cacheFileUrl;
84+
}
85+
finally {
86+
if (fos != null) {
87+
try {
88+
fos.close();
89+
fos = null;
90+
}
91+
catch (IOException e) {
92+
e.printStackTrace();
93+
}
94+
}
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)