uilib-native 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +1,24 @@
1
1
  package com.wix.reactnativeuilib.dynamicfont;
2
2
 
3
+ import android.app.Activity;
4
+ import android.graphics.Typeface;
5
+ import android.util.Base64;
6
+
7
+ import com.facebook.react.bridge.Callback;
3
8
  import com.facebook.react.bridge.ReactApplicationContext;
4
9
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
10
  import com.facebook.react.bridge.ReactMethod;
6
- import com.facebook.react.bridge.Callback;
7
- import com.facebook.react.bridge.Arguments;
8
11
  import com.facebook.react.bridge.ReadableMap;
9
- import com.facebook.react.bridge.WritableMap;
10
12
  import com.facebook.react.views.text.ReactFontManager;
11
13
 
12
- import android.app.Activity;
13
- import android.graphics.Typeface;
14
- import android.util.Base64;
15
-
16
14
  import java.io.File;
17
15
  import java.io.FileOutputStream;
18
- import java.lang.reflect.Field;
19
- import java.util.ArrayList;
20
- import java.util.HashMap;
21
- import java.util.List;
22
- import java.util.Map;
23
- import java.util.Set;
24
16
 
25
17
  public class DynamicFontModule extends ReactContextBaseJavaModule {
26
18
  int tempNameCounter = 0;
27
19
 
28
- private final ReactApplicationContext reactContext;
29
-
30
20
  public DynamicFontModule(ReactApplicationContext reactContext) {
31
21
  super(reactContext);
32
- this.reactContext = reactContext;
33
22
  }
34
23
 
35
24
  @Override
@@ -136,7 +125,7 @@ public class DynamicFontModule extends ReactContextBaseJavaModule {
136
125
  Typeface typeface = Typeface.createFromFile(cacheFile);
137
126
 
138
127
  //Cache the font for react
139
- ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface);
128
+ ReactFontManager.getInstance().setTypeface(name, Typeface.NORMAL, typeface);
140
129
 
141
130
  cacheFile.delete();
142
131
  } catch(Exception e) {
@@ -1,5 +1,5 @@
1
1
  import {Platform} from 'react-native';
2
- import fs from 'react-native-fs';
2
+ import RNFS from './RNFSPackage';
3
3
  import {FontExtension} from './FontLoader';
4
4
 
5
5
  const DEFAULT_DYNAMIC_FONTS_FOLDER = '/dynamicFonts';
@@ -20,6 +20,7 @@ export type FontDownloaderProps = {
20
20
  // TODO: this can probably be a more general "downloader" if we so choose
21
21
  export default class FontDownloader {
22
22
  private readonly props: FontDownloaderProps;
23
+ private readonly fs: NonNullable<typeof RNFS>;
23
24
 
24
25
  constructor(props: FontDownloaderProps) {
25
26
  this.props = {
@@ -27,11 +28,18 @@ export default class FontDownloader {
27
28
  downloadErrorMessage: DEFAULT_DOWNLOAD_ERROR_MESSAGE,
28
29
  ...props
29
30
  };
31
+
32
+ if (!RNFS) {
33
+ throw new Error(`RNUILib FontDownloader requires installing "react-native-fs" dependency`);
34
+ }
35
+ this.fs = RNFS;
30
36
  }
31
37
 
32
38
  private getPrivateFolder() {
33
39
  const {dynamicFontsFolder} = this.props;
34
- return (Platform.OS === 'android' ? fs.ExternalDirectoryPath : fs.DocumentDirectoryPath) + dynamicFontsFolder;
40
+ return (
41
+ (Platform.OS === 'android' ? this.fs.ExternalDirectoryPath : this.fs.DocumentDirectoryPath) + dynamicFontsFolder
42
+ );
35
43
  }
36
44
 
37
45
  private getPrivateFilePath(fileName: string) {
@@ -44,13 +52,13 @@ export default class FontDownloader {
44
52
 
45
53
  private async _isFontDownloaded(fileName: string) {
46
54
  const privateFilePath = this.getPrivateFilePath(fileName);
47
- return await fs.exists(privateFilePath);
55
+ return await this.fs.exists(privateFilePath);
48
56
  }
49
57
 
50
58
  private async createPrivateFolderIfNeeded() {
51
59
  const privateFolder = this.getPrivateFolder();
52
- if (!(await fs.exists(privateFolder))) {
53
- await fs.mkdir(privateFolder);
60
+ if (!(await this.fs.exists(privateFolder))) {
61
+ await this.fs.mkdir(privateFolder);
54
62
  }
55
63
  }
56
64
 
@@ -95,7 +103,8 @@ export default class FontDownloader {
95
103
  const downloadLocation = this.getPrivateFilePath(fileName);
96
104
 
97
105
  try {
98
- const result = await fs.downloadFile(this.getDownloadFontOptions(fontUri, downloadLocation, timeout)).promise;
106
+ const result = await this.fs.downloadFile(this.getDownloadFontOptions(fontUri, downloadLocation, timeout))
107
+ .promise;
99
108
  if (result.statusCode === 200) {
100
109
  return downloadLocation;
101
110
  } else {
@@ -126,8 +135,8 @@ export default class FontDownloader {
126
135
  let base64FontString;
127
136
  const fileName = this.getFileName(fontName, fontExtension);
128
137
  const privateFilePath = this.getPrivateFilePath(fileName);
129
- if (await fs.exists(privateFilePath)) {
130
- base64FontString = await fs.readFile(privateFilePath, 'base64').catch(() => {});
138
+ if (await this.fs.exists(privateFilePath)) {
139
+ base64FontString = await this.fs.readFile(privateFilePath, 'base64').catch(() => {});
131
140
  }
132
141
 
133
142
  return base64FontString;
@@ -0,0 +1,6 @@
1
+ let RNFS: typeof import('react-native-fs') | undefined;
2
+ try {
3
+ RNFS = require('react-native-fs');
4
+ } catch (error) {}
5
+
6
+ export default RNFS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uilib-native",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "homepage": "https://github.com/wix/react-native-ui-lib",
5
5
  "description": "uilib native components (separated from js components)",
6
6
  "main": "components/index.js",