Parcourir la source

add local custom font for demo

iou90 il y a 4 ans
Parent
révision
e20917b542

+ 54
- 39
demo/App.js Voir le fichier

1
-import React, { useState } from 'react';
1
+import React, {useState} from 'react';
2
 
2
 
3
-import { ScrollView, StyleSheet, Text, TouchableOpacity, Platform, Linking } from 'react-native';
3
+import {
4
+  ScrollView,
5
+  StyleSheet,
6
+  Text,
7
+  TouchableOpacity,
8
+  Platform,
9
+  Linking,
10
+} from 'react-native';
4
 
11
 
5
 import AutoHeightWebView from 'react-native-autoheight-webview';
12
 import AutoHeightWebView from 'react-native-autoheight-webview';
6
 
13
 
13
   autoWidthScript,
20
   autoWidthScript,
14
   autoDetectLinkScript,
21
   autoDetectLinkScript,
15
   style0,
22
   style0,
16
-  inlineBodyStyle
23
+  inlineBodyStyle,
17
 } from './config';
24
 } from './config';
18
 
25
 
19
 const onShouldStartLoadWithRequest = result => {
26
 const onShouldStartLoadWithRequest = result => {
21
   return true;
28
   return true;
22
 };
29
 };
23
 
30
 
24
-const onError = ({ nativeEvent }) => console.error('WebView error: ', nativeEvent);
31
+const onError = ({nativeEvent}) =>
32
+  console.error('WebView error: ', nativeEvent);
25
 
33
 
26
 const onMessage = event => {
34
 const onMessage = event => {
27
-  const { data } = event.nativeEvent;
35
+  const {data} = event.nativeEvent;
28
   let messageData;
36
   let messageData;
29
   // maybe parse stringified JSON
37
   // maybe parse stringified JSON
30
   try {
38
   try {
33
     console.log(e.message);
41
     console.log(e.message);
34
   }
42
   }
35
   if (typeof messageData === 'object') {
43
   if (typeof messageData === 'object') {
36
-    const { url } = messageData;
44
+    const {url} = messageData;
37
     // check if this message concerns us
45
     // check if this message concerns us
38
     if (url && url.startsWith('http')) {
46
     if (url && url.startsWith('http')) {
39
-      Linking.openURL(url).catch(error => console.error('An error occurred', error));
47
+      Linking.openURL(url).catch(error =>
48
+        console.error('An error occurred', error),
49
+      );
40
     }
50
     }
41
   }
51
   }
42
 };
52
 };
54
 const onWidthLoadEnd = () => console.log('width on load end');
64
 const onWidthLoadEnd = () => console.log('width on load end');
55
 
65
 
56
 const Explorer = () => {
66
 const Explorer = () => {
57
-  const [{ widthHtml, heightHtml }, setHtml] = useState({
67
+  const [{widthHtml, heightHtml}, setHtml] = useState({
58
     widthHtml: autoWidthHtml0,
68
     widthHtml: autoWidthHtml0,
59
-    heightHtml: autoHeightHtml0
69
+    heightHtml: autoHeightHtml0,
60
   });
70
   });
61
   const changeSource = () =>
71
   const changeSource = () =>
62
     setHtml({
72
     setHtml({
63
       widthHtml: widthHtml === autoWidthHtml0 ? autoWidthHtml1 : autoWidthHtml0,
73
       widthHtml: widthHtml === autoWidthHtml0 ? autoWidthHtml1 : autoWidthHtml0,
64
-      heightHtml: heightHtml === autoHeightHtml0 ? autoHeightHtml1 : autoHeightHtml0
74
+      heightHtml:
75
+        heightHtml === autoHeightHtml0 ? autoHeightHtml1 : autoHeightHtml0,
65
     });
76
     });
66
 
77
 
67
-  const [{ widthStyle, heightStyle }, setStyle] = useState({
78
+  const [{widthStyle, heightStyle}, setStyle] = useState({
68
     heightStyle: null,
79
     heightStyle: null,
69
-    widthStyle: inlineBodyStyle
80
+    widthStyle: inlineBodyStyle,
70
   });
81
   });
71
   const changeStyle = () =>
82
   const changeStyle = () =>
72
     setStyle({
83
     setStyle({
73
-      widthStyle: widthStyle === inlineBodyStyle ? style0 + inlineBodyStyle : inlineBodyStyle,
74
-      heightStyle: heightStyle === null ? style0 : null
84
+      widthStyle:
85
+        widthStyle === inlineBodyStyle
86
+          ? style0 + inlineBodyStyle
87
+          : inlineBodyStyle,
88
+      heightStyle: heightStyle === null ? style0 : null,
75
     });
89
     });
76
 
90
 
77
-  const [{ widthScript, heightScript }, setScript] = useState({
91
+  const [{widthScript, heightScript}, setScript] = useState({
78
     heightScript: autoDetectLinkScript,
92
     heightScript: autoDetectLinkScript,
79
-    widthScript: null
93
+    widthScript: null,
80
   });
94
   });
81
   const changeScript = () =>
95
   const changeScript = () =>
82
     setScript({
96
     setScript({
83
       widthScript: widthScript == autoWidthScript ? autoWidthScript : null,
97
       widthScript: widthScript == autoWidthScript ? autoWidthScript : null,
84
       heightScript:
98
       heightScript:
85
-        heightScript !== autoDetectLinkScript ? autoDetectLinkScript : autoHeightScript + autoDetectLinkScript
99
+        heightScript !== autoDetectLinkScript
100
+          ? autoDetectLinkScript
101
+          : autoHeightScript + autoDetectLinkScript,
86
     });
102
     });
87
 
103
 
88
-  const [heightSize, setHeightSize] = useState({ height: 0, width: 0 });
89
-  const [widthSize, setWidthSize] = useState({ height: 0, width: 0 });
104
+  const [heightSize, setHeightSize] = useState({height: 0, width: 0});
105
+  const [widthSize, setWidthSize] = useState({height: 0, width: 0});
90
 
106
 
91
   return (
107
   return (
92
     <ScrollView
108
     <ScrollView
93
       style={{
109
       style={{
94
         paddingTop: 45,
110
         paddingTop: 45,
95
-        backgroundColor: 'lightyellow'
111
+        backgroundColor: 'lightyellow',
96
       }}
112
       }}
97
       contentContainerStyle={{
113
       contentContainerStyle={{
98
         justifyContent: 'center',
114
         justifyContent: 'center',
99
-        alignItems: 'center'
100
-      }}
101
-    >
115
+        alignItems: 'center',
116
+      }}>
102
       <AutoHeightWebView
117
       <AutoHeightWebView
103
         customStyle={heightStyle}
118
         customStyle={heightStyle}
104
         onError={onError}
119
         onError={onError}
107
         onLoadEnd={onHeightLoadEnd}
122
         onLoadEnd={onHeightLoadEnd}
108
         onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
123
         onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
109
         onSizeUpdated={setHeightSize}
124
         onSizeUpdated={setHeightSize}
110
-        source={{ html: heightHtml }}
125
+        source={{html: heightHtml}}
111
         customScript={heightScript}
126
         customScript={heightScript}
112
         onMessage={onMessage}
127
         onMessage={onMessage}
113
       />
128
       />
114
-      <Text style={{ padding: 5 }}>
129
+      <Text style={{padding: 5}}>
115
         height: {heightSize.height}, width: {heightSize.width}
130
         height: {heightSize.height}, width: {heightSize.width}
116
       </Text>
131
       </Text>
117
       <AutoHeightWebView
132
       <AutoHeightWebView
118
-        baseUrl={Platform.OS === 'android' ? 'file:///android_asset/webAssets/' : 'webAssets/'}
119
         style={{
133
         style={{
120
-          marginTop: 15
134
+          marginTop: 15,
121
         }}
135
         }}
122
         enableBaseUrl
136
         enableBaseUrl
123
-        files={[
124
-          {
125
-            href: 'demo.css',
126
-            type: 'text/css',
127
-            rel: 'stylesheet'
128
-          }
129
-        ]}
130
         customStyle={widthStyle}
137
         customStyle={widthStyle}
131
         onError={onError}
138
         onError={onError}
132
         onLoad={onWidthLoad}
139
         onLoad={onWidthLoad}
134
         onLoadEnd={onWidthLoadEnd}
141
         onLoadEnd={onWidthLoadEnd}
135
         onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
142
         onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
136
         onSizeUpdated={setWidthSize}
143
         onSizeUpdated={setWidthSize}
137
-        source={{ html: widthHtml }}
144
+        allowFileAccessFromFileURLs={true}
145
+        allowUniversalAccessFromFileURLs={true}
146
+        source={{
147
+          html: widthHtml,
148
+          baseUrl:
149
+            Platform.OS === 'android' ? 'file:///android_asset/' : 'web/',
150
+        }}
138
         customScript={widthScript}
151
         customScript={widthScript}
139
       />
152
       />
140
-      <Text style={{ padding: 5 }}>
153
+      <Text style={{padding: 5}}>
141
         height: {widthSize.height}, width: {widthSize.width}
154
         height: {widthSize.height}, width: {widthSize.width}
142
       </Text>
155
       </Text>
143
       <TouchableOpacity onPress={changeSource} style={styles.button}>
156
       <TouchableOpacity onPress={changeSource} style={styles.button}>
146
       <TouchableOpacity onPress={changeStyle} style={styles.button}>
159
       <TouchableOpacity onPress={changeStyle} style={styles.button}>
147
         <Text>change style</Text>
160
         <Text>change style</Text>
148
       </TouchableOpacity>
161
       </TouchableOpacity>
149
-      <TouchableOpacity onPress={changeScript} style={[styles.button, { marginBottom: 100 }]}>
162
+      <TouchableOpacity
163
+        onPress={changeScript}
164
+        style={[styles.button, {marginBottom: 100}]}>
150
         <Text>change script</Text>
165
         <Text>change script</Text>
151
       </TouchableOpacity>
166
       </TouchableOpacity>
152
     </ScrollView>
167
     </ScrollView>
158
     marginTop: 15,
173
     marginTop: 15,
159
     backgroundColor: 'aliceblue',
174
     backgroundColor: 'aliceblue',
160
     borderRadius: 5,
175
     borderRadius: 5,
161
-    padding: 5
162
-  }
176
+    padding: 5,
177
+  },
163
 });
178
 });
164
 
179
 
165
 export default Explorer;
180
 export default Explorer;

BIN
demo/android/app/src/main/assets/ae_AlArabiya.ttf Voir le fichier


+ 7
- 1
demo/config.js Voir le fichier

20
 `;
20
 `;
21
 
21
 
22
 const inlineBodyStyle = `
22
 const inlineBodyStyle = `
23
+    @font-face {
24
+      font-family: ae_AlArabiya;
25
+      src:url("ae_AlArabiya.ttf");
26
+    }
27
+
23
     body {
28
     body {
29
+        font-family: ae_AlArabiya;
24
         display: inline-block;
30
         display: inline-block;
25
     }
31
     }
26
 `;
32
 `;
50
 const autoWidthHtml0 = `
56
 const autoWidthHtml0 = `
51
 <html>
57
 <html>
52
 <head>
58
 <head>
53
-  <meta name="viewport" content="target-densitydpi=device-dpi, initial-scale=1.0, user-scalable=no" />
59
+  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
54
 </head>
60
 </head>
55
 <p class="localStyle" style="display: inline;background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;padding-top:0;padding-bottom:0;">hey</p>
61
 <p class="localStyle" style="display: inline;background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;padding-top:0;padding-bottom:0;">hey</p>
56
 </html>
62
 </html>

+ 14
- 2
demo/ios/demo.xcodeproj/project.pbxproj Voir le fichier

19
 		428E7C00A1DF1C1A2C1140EE /* libPods-demoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 34E943675B55A190041D9BC6 /* libPods-demoTests.a */; };
19
 		428E7C00A1DF1C1A2C1140EE /* libPods-demoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 34E943675B55A190041D9BC6 /* libPods-demoTests.a */; };
20
 		5D9570ED1A0B682B5FF5E421 /* libPods-demo-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 821EC82BD30472D6D387B788 /* libPods-demo-tvOSTests.a */; };
20
 		5D9570ED1A0B682B5FF5E421 /* libPods-demo-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 821EC82BD30472D6D387B788 /* libPods-demo-tvOSTests.a */; };
21
 		A50903E452D634CE572F43CD /* libPods-demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8486CCD792395AAD80956F45 /* libPods-demo.a */; };
21
 		A50903E452D634CE572F43CD /* libPods-demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8486CCD792395AAD80956F45 /* libPods-demo.a */; };
22
+		B7C1B3872394B353001240AA /* ae_AlArabiya.ttf in Resources */ = {isa = PBXBuildFile; fileRef = B7C1B3862394B353001240AA /* ae_AlArabiya.ttf */; };
22
 		EFB606294F69E6FA304BD500 /* libPods-demo-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D8370FC4C13D1AE1CC8852B /* libPods-demo-tvOS.a */; };
23
 		EFB606294F69E6FA304BD500 /* libPods-demo-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9D8370FC4C13D1AE1CC8852B /* libPods-demo-tvOS.a */; };
23
 /* End PBXBuildFile section */
24
 /* End PBXBuildFile section */
24
 
25
 
62
 		914896C0CEFDAA592DADF952 /* Pods-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo.release.xcconfig"; path = "Target Support Files/Pods-demo/Pods-demo.release.xcconfig"; sourceTree = "<group>"; };
63
 		914896C0CEFDAA592DADF952 /* Pods-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo.release.xcconfig"; path = "Target Support Files/Pods-demo/Pods-demo.release.xcconfig"; sourceTree = "<group>"; };
63
 		9D8370FC4C13D1AE1CC8852B /* libPods-demo-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-demo-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
64
 		9D8370FC4C13D1AE1CC8852B /* libPods-demo-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-demo-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
64
 		A74FCF62A73172586BCD1E8C /* Pods-demo-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOS.release.xcconfig"; path = "Target Support Files/Pods-demo-tvOS/Pods-demo-tvOS.release.xcconfig"; sourceTree = "<group>"; };
65
 		A74FCF62A73172586BCD1E8C /* Pods-demo-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOS.release.xcconfig"; path = "Target Support Files/Pods-demo-tvOS/Pods-demo-tvOS.release.xcconfig"; sourceTree = "<group>"; };
66
+		B7C1B3862394B353001240AA /* ae_AlArabiya.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = ae_AlArabiya.ttf; sourceTree = "<group>"; };
65
 		B932E4CF7C7ADA47E0C72933 /* Pods-demo-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOSTests.debug.xcconfig"; path = "Target Support Files/Pods-demo-tvOSTests/Pods-demo-tvOSTests.debug.xcconfig"; sourceTree = "<group>"; };
67
 		B932E4CF7C7ADA47E0C72933 /* Pods-demo-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOSTests.debug.xcconfig"; path = "Target Support Files/Pods-demo-tvOSTests/Pods-demo-tvOSTests.debug.xcconfig"; sourceTree = "<group>"; };
66
 		BB1DF6C3AB03F9FA00E48CAE /* Pods-demo-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-demo-tvOS/Pods-demo-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
68
 		BB1DF6C3AB03F9FA00E48CAE /* Pods-demo-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-demo-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-demo-tvOS/Pods-demo-tvOS.debug.xcconfig"; sourceTree = "<group>"; };
67
 		ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
69
 		ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
148
 				43307E7576B385875B79FCDF /* Pods-demoTests.debug.xcconfig */,
150
 				43307E7576B385875B79FCDF /* Pods-demoTests.debug.xcconfig */,
149
 				150E6CAFA5EF11AE47ED825C /* Pods-demoTests.release.xcconfig */,
151
 				150E6CAFA5EF11AE47ED825C /* Pods-demoTests.release.xcconfig */,
150
 			);
152
 			);
151
-			name = Pods;
152
 			path = Pods;
153
 			path = Pods;
153
 			sourceTree = "<group>";
154
 			sourceTree = "<group>";
154
 		};
155
 		};
175
 		83CBB9F61A601CBA00E9B192 = {
176
 		83CBB9F61A601CBA00E9B192 = {
176
 			isa = PBXGroup;
177
 			isa = PBXGroup;
177
 			children = (
178
 			children = (
179
+				B7C1B3852394B30A001240AA /* web */,
178
 				13B07FAE1A68108700A75B9A /* demo */,
180
 				13B07FAE1A68108700A75B9A /* demo */,
179
 				832341AE1AAA6A7D00B99B32 /* Libraries */,
181
 				832341AE1AAA6A7D00B99B32 /* Libraries */,
180
 				00E356EF1AD99517003FC87E /* demoTests */,
182
 				00E356EF1AD99517003FC87E /* demoTests */,
198
 			name = Products;
200
 			name = Products;
199
 			sourceTree = "<group>";
201
 			sourceTree = "<group>";
200
 		};
202
 		};
203
+		B7C1B3852394B30A001240AA /* web */ = {
204
+			isa = PBXGroup;
205
+			children = (
206
+				B7C1B3862394B353001240AA /* ae_AlArabiya.ttf */,
207
+			);
208
+			path = web;
209
+			sourceTree = "<group>";
210
+		};
201
 /* End PBXGroup section */
211
 /* End PBXGroup section */
202
 
212
 
203
 /* Begin PBXNativeTarget section */
213
 /* Begin PBXNativeTarget section */
308
 			developmentRegion = English;
318
 			developmentRegion = English;
309
 			hasScannedForEncodings = 0;
319
 			hasScannedForEncodings = 0;
310
 			knownRegions = (
320
 			knownRegions = (
321
+				English,
311
 				en,
322
 				en,
312
 				Base,
323
 				Base,
313
 			);
324
 			);
338
 			files = (
349
 			files = (
339
 				13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
350
 				13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
340
 				13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
351
 				13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
352
+				B7C1B3872394B353001240AA /* ae_AlArabiya.ttf in Resources */,
341
 			);
353
 			);
342
 			runOnlyForDeploymentPostprocessing = 0;
354
 			runOnlyForDeploymentPostprocessing = 0;
343
 		};
355
 		};
920
 /* End XCConfigurationList section */
932
 /* End XCConfigurationList section */
921
 	};
933
 	};
922
 	rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
934
 	rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
923
-}
935
+}

BIN
demo/ios/web/ae_AlArabiya.ttf Voir le fichier