Skip to content

Commit cdc4929

Browse files
authored
Merge pull request #55 from souvik-ghosh/update_17
Update example
2 parents 82a9975 + ca307e7 commit cdc4929

39 files changed

+7580
-1171
lines changed

example/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Windows files
2+
[*.bat]
3+
end_of_line = crlf

example/.flowconfig

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
; Ignore polyfills
99
node_modules/react-native/Libraries/polyfills/.*
1010

11-
; These should not be required directly
12-
; require from fbjs/lib instead: require('fbjs/lib/warning')
13-
node_modules/warning/.*
14-
1511
; Flow doesn't support platforms
1612
.*/Libraries/Utilities/LoadingView.js
1713

@@ -21,34 +17,30 @@ node_modules/warning/.*
2117
[include]
2218

2319
[libs]
24-
node_modules/react-native/Libraries/react-native/react-native-interface.js
20+
node_modules/react-native/interface.js
2521
node_modules/react-native/flow/
2622

2723
[options]
2824
emoji=true
2925

30-
esproposal.optional_chaining=enable
31-
esproposal.nullish_coalescing=enable
26+
exact_by_default=true
27+
28+
format.bracket_spacing=false
3229

3330
module.file_ext=.js
3431
module.file_ext=.json
3532
module.file_ext=.ios.js
3633

3734
munge_underscores=true
3835

39-
module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation'
4036
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
41-
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
37+
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
4238

4339
suppress_type=$FlowIssue
4440
suppress_type=$FlowFixMe
4541
suppress_type=$FlowFixMeProps
4642
suppress_type=$FlowFixMeState
4743

48-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
49-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
50-
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
51-
5244
[lints]
5345
sketchy-null-number=warn
5446
sketchy-null-mixed=warn
@@ -57,10 +49,8 @@ untyped-type-import=warn
5749
nonstrict-import=warn
5850
deprecated-type=warn
5951
unsafe-getters-setters=warn
60-
inexact-spread=warn
6152
unnecessary-invariant=warn
6253
signature-verification-failure=warn
63-
deprecated-utility=error
6454

6555
[strict]
6656
deprecated-type
@@ -72,4 +62,4 @@ untyped-import
7262
untyped-type-import
7363

7464
[version]
75-
^0.105.0
65+
^0.158.0

example/.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
*.pbxproj -text
1+
# Windows files should use crlf line endings
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
*.bat text eol=crlf

example/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ build/
2828
.gradle
2929
local.properties
3030
*.iml
31+
*.hprof
3132

3233
# node.js
3334
#
3435
node_modules/
3536
npm-debug.log
3637
yarn-error.log
37-
yarn.lock
3838

3939
# BUCK
4040
buck-out/

example/.prettierrc.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
module.exports = {};
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
arrowParens: 'avoid',
7+
};

example/App.js

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
import React, { useState } from "react";
2-
import { Image, Text, View, StyleSheet, TextInput, Button } from "react-native";
3-
import { createThumbnail } from "react-native-create-thumbnail";
1+
import React, {useState} from 'react';
2+
import {
3+
Image,
4+
Text,
5+
View,
6+
StyleSheet,
7+
TextInput,
8+
Button,
9+
ActivityIndicator,
10+
} from 'react-native';
11+
import {createThumbnail} from 'react-native-create-thumbnail';
12+
13+
const placeholderImage = require('./assets/placeholder-image.png');
414

515
export default function App() {
616
const [path, setPath] = useState('');
717
const [thumbnail, setThumbnail] = useState('');
8-
const [timeStamp, setTimeStamp] = useState('');
9-
10-
const generate = () => {
11-
if (!path) {
12-
return;
13-
}
14-
15-
createThumbnail({
16-
url: path,
17-
timeStamp: parseInt(timeStamp)
18-
})
19-
.then(response => {
20-
setThumbnail(response.path);
21-
})
22-
.catch(err => console.log({ err }));
23-
};
18+
const [timeStamp, setTimeStamp] = useState('1000');
19+
const [isLoading, setIsLoading] = useState(false);
2420

2521
return (
2622
<View style={styles.container}>
@@ -32,56 +28,86 @@ export default function App() {
3228
placeholder="Paste video url"
3329
/>
3430
<TextInput
31+
keyboardType="numeric"
3532
value={timeStamp}
3633
onChangeText={setTimeStamp}
3734
style={styles.timeInput}
3835
placeholder="Timestamp"
3936
/>
4037
<Button
4138
title="Generate Thumbnail"
42-
onPress={generate}
39+
disabled={isLoading}
40+
onPress={generateThumbnail}
4341
/>
4442
<Text style={styles.welcome}>☆THUMBNAIL☆</Text>
45-
{!!thumbnail && (
46-
<Image style={styles.image} source={{ uri: thumbnail }} />
47-
)}
43+
<View style={styles.image}>
44+
{isLoading ? (
45+
<ActivityIndicator size="large" />
46+
) : (
47+
<Image
48+
style={styles.image}
49+
source={thumbnail ? {uri: thumbnail} : placeholderImage}
50+
/>
51+
)}
52+
</View>
4853
</View>
4954
);
55+
56+
async function generateThumbnail() {
57+
if (!path) {
58+
return;
59+
}
60+
61+
setIsLoading(true);
62+
63+
try {
64+
const response = await createThumbnail({
65+
url: path,
66+
timeStamp: parseInt(timeStamp, 10),
67+
});
68+
setThumbnail(response.path);
69+
} catch (err) {
70+
console.log({err});
71+
} finally {
72+
setIsLoading(false);
73+
}
74+
}
5075
}
5176

5277
const styles = StyleSheet.create({
5378
container: {
5479
flex: 1,
55-
justifyContent: "center",
56-
alignItems: "center",
57-
backgroundColor: "#F5FCFF"
80+
justifyContent: 'center',
81+
alignItems: 'center',
82+
backgroundColor: '#F5FCFF',
5883
},
5984
welcome: {
6085
fontSize: 20,
61-
textAlign: "center",
62-
margin: 10
86+
textAlign: 'center',
87+
margin: 20,
6388
},
6489
instructions: {
65-
textAlign: "center",
66-
color: "#333333",
67-
marginBottom: 5
90+
textAlign: 'center',
91+
color: '#333333',
92+
marginBottom: 20,
6893
},
6994
image: {
7095
height: 150,
7196
width: 250,
72-
backgroundColor: "lightgrey"
97+
backgroundColor: 'lightgrey',
98+
justifyContent: 'center',
7399
},
74100
pathInput: {
75-
height: 35,
76101
backgroundColor: '#eaeaea',
77102
width: '80%',
78-
paddingHorizontal: 10
103+
paddingHorizontal: 10,
104+
color: 'black',
79105
},
80106
timeInput: {
81-
height: 35,
82107
backgroundColor: '#eaeaea',
83108
width: '40%',
84109
paddingHorizontal: 10,
85-
marginTop: 10
86-
}
110+
margin: 20,
111+
color: 'black',
112+
},
87113
});

example/android/app/build.gradle

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import com.android.build.OutputFile
1515
* // the name of the generated asset file containing your JS bundle
1616
* bundleAssetName: "index.android.bundle",
1717
*
18-
* // the entry file for bundle generation
18+
* // the entry file for bundle generation. If none specified and
19+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
20+
* // default. Can be overridden with ENTRY_FILE environment variable.
1921
* entryFile: "index.android.js",
2022
*
21-
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
23+
* // https://reactnative.dev/docs/performance#enable-the-ram-format
2224
* bundleCommand: "ram-bundle",
2325
*
2426
* // whether to bundle JS and assets in debug mode
@@ -76,7 +78,6 @@ import com.android.build.OutputFile
7678
*/
7779

7880
project.ext.react = [
79-
entryFile: "index.js",
8081
enableHermes: false, // clean and rebuild if changing
8182
]
8283

@@ -119,13 +120,15 @@ def jscFlavor = 'org.webkit:android-jsc:+'
119120
*/
120121
def enableHermes = project.ext.react.get("enableHermes", false);
121122

123+
/**
124+
* Architectures to build native code for in debug.
125+
*/
126+
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
127+
122128
android {
123-
compileSdkVersion rootProject.ext.compileSdkVersion
129+
ndkVersion rootProject.ext.ndkVersion
124130

125-
compileOptions {
126-
sourceCompatibility JavaVersion.VERSION_1_8
127-
targetCompatibility JavaVersion.VERSION_1_8
128-
}
131+
compileSdkVersion rootProject.ext.compileSdkVersion
129132

130133
defaultConfig {
131134
applicationId "com.example"
@@ -153,25 +156,32 @@ android {
153156
buildTypes {
154157
debug {
155158
signingConfig signingConfigs.debug
159+
if (nativeArchitectures) {
160+
ndk {
161+
abiFilters nativeArchitectures.split(',')
162+
}
163+
}
156164
}
157165
release {
158166
// Caution! In production, you need to generate your own keystore file.
159-
// see https://facebook.github.io/react-native/docs/signed-apk-android.
167+
// see https://reactnative.dev/docs/signed-apk-android.
160168
signingConfig signingConfigs.debug
161169
minifyEnabled enableProguardInReleaseBuilds
162170
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163171
}
164172
}
173+
165174
// applicationVariants are e.g. debug, release
166175
applicationVariants.all { variant ->
167176
variant.outputs.each { output ->
168177
// For each separate APK per architecture, set a unique version code as described here:
169178
// https://developer.android.com/studio/build/configure-apk-splits.html
179+
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
170180
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
171181
def abi = output.getFilter(OutputFile.ABI)
172182
if (abi != null) { // null for the universal-debug, universal-release variants
173183
output.versionCodeOverride =
174-
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
184+
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
175185
}
176186

177187
}
@@ -180,8 +190,24 @@ android {
180190

181191
dependencies {
182192
implementation fileTree(dir: "libs", include: ["*.jar"])
193+
//noinspection GradleDynamicVersion
183194
implementation "com.facebook.react:react-native:+" // From node_modules
184195

196+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
197+
198+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
199+
exclude group:'com.facebook.fbjni'
200+
}
201+
202+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
203+
exclude group:'com.facebook.flipper'
204+
exclude group:'com.squareup.okhttp3', module:'okhttp'
205+
}
206+
207+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
208+
exclude group:'com.facebook.flipper'
209+
}
210+
185211
if (enableHermes) {
186212
def hermesPath = "../../node_modules/hermes-engine/android/";
187213
debugImplementation files(hermesPath + "hermes-debug.aar")
@@ -194,7 +220,7 @@ dependencies {
194220
// Run this once to be able to run the application with BUCK
195221
// puts all compile dependencies into folder libs for BUCK to use
196222
task copyDownloadableDepsToLibs(type: Copy) {
197-
from configurations.compile
223+
from configurations.implementation
198224
into 'libs'
199225
}
200226

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
66

7-
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
7+
<application
8+
android:usesCleartextTraffic="true"
9+
tools:targetApi="28"
10+
tools:ignore="GoogleAppIndexingWarning">
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
12+
</application>
813
</manifest>

0 commit comments

Comments
 (0)