Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
665931f7b9 | |||
d2054b028a | |||
b83407f1f4 | |||
f1f969c8ea | |||
880c20661e | |||
f635c9d961 | |||
5a35191d12 |
@@ -28,6 +28,21 @@
|
|||||||
<data android:mimeType="image/png" />
|
<data android:mimeType="image/png" />
|
||||||
<data android:mimeType="image/webp" />
|
<data android:mimeType="image/webp" />
|
||||||
<data android:mimeType="image/gif" />
|
<data android:mimeType="image/gif" />
|
||||||
|
<data android:mimeType="video/av01" />
|
||||||
|
<data android:mimeType="video/3gpp" />
|
||||||
|
<data android:mimeType="video/avc" />
|
||||||
|
<data android:mimeType="video/hevc" />
|
||||||
|
<data android:mimeType="video/x-matroska" />
|
||||||
|
<data android:mimeType="video/mp2t" />
|
||||||
|
<data android:mimeType="video/mp4" />
|
||||||
|
<data android:mimeType="video/mp42" />
|
||||||
|
<data android:mimeType="video/mp43" />
|
||||||
|
<data android:mimeType="video/mp4v-es" />
|
||||||
|
<data android:mimeType="video/mpeg" />
|
||||||
|
<data android:mimeType="video/mpeg2" />
|
||||||
|
<data android:mimeType="video/x-vnd.on2.vp8" />
|
||||||
|
<data android:mimeType="video/x-vnd.on2.vp9" />
|
||||||
|
<data android:mimeType="video/webm" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||||
@@ -37,6 +52,21 @@
|
|||||||
<data android:mimeType="image/png" />
|
<data android:mimeType="image/png" />
|
||||||
<data android:mimeType="image/webp" />
|
<data android:mimeType="image/webp" />
|
||||||
<data android:mimeType="image/gif" />
|
<data android:mimeType="image/gif" />
|
||||||
|
<data android:mimeType="video/av01" />
|
||||||
|
<data android:mimeType="video/3gpp" />
|
||||||
|
<data android:mimeType="video/avc" />
|
||||||
|
<data android:mimeType="video/hevc" />
|
||||||
|
<data android:mimeType="video/x-matroska" />
|
||||||
|
<data android:mimeType="video/mp2t" />
|
||||||
|
<data android:mimeType="video/mp4" />
|
||||||
|
<data android:mimeType="video/mp42" />
|
||||||
|
<data android:mimeType="video/mp43" />
|
||||||
|
<data android:mimeType="video/mp4v-es" />
|
||||||
|
<data android:mimeType="video/mpeg" />
|
||||||
|
<data android:mimeType="video/mpeg2" />
|
||||||
|
<data android:mimeType="video/x-vnd.on2.vp8" />
|
||||||
|
<data android:mimeType="video/x-vnd.on2.vp9" />
|
||||||
|
<data android:mimeType="video/webm" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
83
package-lock.json
generated
83
package-lock.json
generated
@@ -12,12 +12,14 @@
|
|||||||
"@bankify/redux-persist-realm": "^0.1.3",
|
"@bankify/redux-persist-realm": "^0.1.3",
|
||||||
"@react-native-clipboard/clipboard": "^1.11.2",
|
"@react-native-clipboard/clipboard": "^1.11.2",
|
||||||
"@react-native-community/hooks": "^3.0.0",
|
"@react-native-community/hooks": "^3.0.0",
|
||||||
|
"@react-native-ml-kit/text-recognition": "^1.2.1",
|
||||||
"@react-navigation/bottom-tabs": "^6.5.8",
|
"@react-navigation/bottom-tabs": "^6.5.8",
|
||||||
"@react-navigation/native": "^6.1.7",
|
"@react-navigation/native": "^6.1.7",
|
||||||
"@react-navigation/native-stack": "^6.9.13",
|
"@react-navigation/native-stack": "^6.9.13",
|
||||||
"@realm/react": "^0.5.1",
|
"@realm/react": "^0.5.1",
|
||||||
"@reduxjs/toolkit": "^1.9.5",
|
"@reduxjs/toolkit": "^1.9.5",
|
||||||
"@shopify/flash-list": "^1.4.3",
|
"@shopify/flash-list": "^1.4.3",
|
||||||
|
"magic-bytes.js": "^1.0.15",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-native": "0.72.2",
|
"react-native": "0.72.2",
|
||||||
"react-native-document-picker": "^9.0.1",
|
"react-native-document-picker": "^9.0.1",
|
||||||
@@ -4112,6 +4114,15 @@
|
|||||||
"react-native": ">=0.65"
|
"react-native": ">=0.65"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@react-native-ml-kit/text-recognition": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@react-native-ml-kit/text-recognition/-/text-recognition-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-pJrnf8AvihzYdPAZoZZEeKbOUOMjdsetDjHlleXOoVcoPo6qjfh6Il/Q0ey3boIQuO3HglvNjcMPGEPThF3sPA==",
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">=16.8.1",
|
||||||
|
"react-native": ">=0.60.0-rc.0 <1.0.x"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@react-native/assets-registry": {
|
"node_modules/@react-native/assets-registry": {
|
||||||
"version": "0.72.0",
|
"version": "0.72.0",
|
||||||
"resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.72.0.tgz",
|
"resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.72.0.tgz",
|
||||||
@@ -5617,6 +5628,29 @@
|
|||||||
"readable-stream": "^3.4.0"
|
"readable-stream": "^3.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/bl/node_modules/buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/brace-expansion": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
@@ -5687,7 +5721,7 @@
|
|||||||
"node": ">=6.9.0"
|
"node": ">=6.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/buffer": {
|
"node_modules/bson/node_modules/buffer": {
|
||||||
"version": "5.7.1",
|
"version": "5.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
@@ -11095,6 +11129,11 @@
|
|||||||
"yallist": "^3.0.2"
|
"yallist": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/magic-bytes.js": {
|
||||||
|
"version": "1.0.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.0.15.tgz",
|
||||||
|
"integrity": "sha512-bpRmwbRHqongRhA+mXzbLWjVy7ylqmfMBYaQkSs6pac0z6hBTvsgrH0r4FBYd/UYVJBmS6Rp/O+oCCQVLzKV1g=="
|
||||||
|
},
|
||||||
"node_modules/magic-string": {
|
"node_modules/magic-string": {
|
||||||
"version": "0.30.1",
|
"version": "0.30.1",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.1.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.1.tgz",
|
||||||
@@ -18770,6 +18809,12 @@
|
|||||||
"integrity": "sha512-g2OyxXHfwIytXUJitBR6Z/ISoOfp0WKx5FOv+NqJ/CrWjRDcTw6zXE5I1C9axfuh30kJqzWchVfCDrkzZYTxqg==",
|
"integrity": "sha512-g2OyxXHfwIytXUJitBR6Z/ISoOfp0WKx5FOv+NqJ/CrWjRDcTw6zXE5I1C9axfuh30kJqzWchVfCDrkzZYTxqg==",
|
||||||
"requires": {}
|
"requires": {}
|
||||||
},
|
},
|
||||||
|
"@react-native-ml-kit/text-recognition": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@react-native-ml-kit/text-recognition/-/text-recognition-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-pJrnf8AvihzYdPAZoZZEeKbOUOMjdsetDjHlleXOoVcoPo6qjfh6Il/Q0ey3boIQuO3HglvNjcMPGEPThF3sPA==",
|
||||||
|
"requires": {}
|
||||||
|
},
|
||||||
"@react-native/assets-registry": {
|
"@react-native/assets-registry": {
|
||||||
"version": "0.72.0",
|
"version": "0.72.0",
|
||||||
"resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.72.0.tgz",
|
"resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.72.0.tgz",
|
||||||
@@ -19947,6 +19992,17 @@
|
|||||||
"buffer": "^5.5.0",
|
"buffer": "^5.5.0",
|
||||||
"inherits": "^2.0.4",
|
"inherits": "^2.0.4",
|
||||||
"readable-stream": "^3.4.0"
|
"readable-stream": "^3.4.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"buffer": {
|
||||||
|
"version": "5.7.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
|
"requires": {
|
||||||
|
"base64-js": "^1.3.1",
|
||||||
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
@@ -19991,15 +20047,17 @@
|
|||||||
"integrity": "sha512-Uu4OCZa0jouQJCKOk1EmmyqtdWAP5HVLru4lQxTwzJzxT+sJ13lVpEZU/MATDxtHiekWMAL84oQY3Xn1LpJVSg==",
|
"integrity": "sha512-Uu4OCZa0jouQJCKOk1EmmyqtdWAP5HVLru4lQxTwzJzxT+sJ13lVpEZU/MATDxtHiekWMAL84oQY3Xn1LpJVSg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"buffer": "^5.6.0"
|
"buffer": "^5.6.0"
|
||||||
}
|
},
|
||||||
},
|
"dependencies": {
|
||||||
"buffer": {
|
"buffer": {
|
||||||
"version": "5.7.1",
|
"version": "5.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
|
||||||
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"base64-js": "^1.3.1",
|
"base64-js": "^1.3.1",
|
||||||
"ieee754": "^1.1.13"
|
"ieee754": "^1.1.13"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"buffer-from": {
|
"buffer-from": {
|
||||||
@@ -23979,6 +24037,11 @@
|
|||||||
"yallist": "^3.0.2"
|
"yallist": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"magic-bytes.js": {
|
||||||
|
"version": "1.0.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.0.15.tgz",
|
||||||
|
"integrity": "sha512-bpRmwbRHqongRhA+mXzbLWjVy7ylqmfMBYaQkSs6pac0z6hBTvsgrH0r4FBYd/UYVJBmS6Rp/O+oCCQVLzKV1g=="
|
||||||
|
},
|
||||||
"magic-string": {
|
"magic-string": {
|
||||||
"version": "0.30.1",
|
"version": "0.30.1",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.1.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.1.tgz",
|
||||||
|
@@ -17,12 +17,14 @@
|
|||||||
"@bankify/redux-persist-realm": "^0.1.3",
|
"@bankify/redux-persist-realm": "^0.1.3",
|
||||||
"@react-native-clipboard/clipboard": "^1.11.2",
|
"@react-native-clipboard/clipboard": "^1.11.2",
|
||||||
"@react-native-community/hooks": "^3.0.0",
|
"@react-native-community/hooks": "^3.0.0",
|
||||||
|
"@react-native-ml-kit/text-recognition": "^1.2.1",
|
||||||
"@react-navigation/bottom-tabs": "^6.5.8",
|
"@react-navigation/bottom-tabs": "^6.5.8",
|
||||||
"@react-navigation/native": "^6.1.7",
|
"@react-navigation/native": "^6.1.7",
|
||||||
"@react-navigation/native-stack": "^6.9.13",
|
"@react-navigation/native-stack": "^6.9.13",
|
||||||
"@realm/react": "^0.5.1",
|
"@realm/react": "^0.5.1",
|
||||||
"@reduxjs/toolkit": "^1.9.5",
|
"@reduxjs/toolkit": "^1.9.5",
|
||||||
"@shopify/flash-list": "^1.4.3",
|
"@shopify/flash-list": "^1.4.3",
|
||||||
|
"magic-bytes.js": "^1.0.15",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-native": "0.72.2",
|
"react-native": "0.72.2",
|
||||||
"react-native-document-picker": "^9.0.1",
|
"react-native-document-picker": "^9.0.1",
|
||||||
|
169
patches/react-native-file-access+3.0.4.patch
Normal file
169
patches/react-native-file-access+3.0.4.patch
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
diff --git a/node_modules/react-native-file-access/README.md b/node_modules/react-native-file-access/README.md
|
||||||
|
index e0540e0..9eb3295 100644
|
||||||
|
--- a/node_modules/react-native-file-access/README.md
|
||||||
|
+++ b/node_modules/react-native-file-access/README.md
|
||||||
|
@@ -155,6 +155,12 @@ type ManagedFetchResult = {
|
||||||
|
- Read the content of a file.
|
||||||
|
- Default encoding of returned string is utf8.
|
||||||
|
|
||||||
|
+`FileSystem.read(path: string, length?: number, position?: number): Promise<number[]>`
|
||||||
|
+
|
||||||
|
+- Read a file as a byte array.
|
||||||
|
+ - `length` - Optional number of bytes to read.
|
||||||
|
+ - `position` - Optional position to start reading from.
|
||||||
|
+
|
||||||
|
```
|
||||||
|
FileSystem.stat(path: string): Promise<FileStat>
|
||||||
|
|
||||||
|
diff --git a/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt b/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt
|
||||||
|
index 248a938..cbd4fe7 100644
|
||||||
|
--- a/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt
|
||||||
|
+++ b/node_modules/react-native-file-access/android/src/main/java/com/alpha0010/fs/FileAccessModule.kt
|
||||||
|
@@ -13,6 +13,8 @@ import com.facebook.react.bridge.Promise
|
||||||
|
import com.facebook.react.bridge.ReactApplicationContext
|
||||||
|
import com.facebook.react.bridge.ReactMethod
|
||||||
|
import com.facebook.react.bridge.ReadableMap
|
||||||
|
+import com.facebook.react.bridge.WritableArray
|
||||||
|
+import com.facebook.react.bridge.WritableNativeArray
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
@@ -400,6 +402,27 @@ class FileAccessModule internal constructor(context: ReactApplicationContext) :
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ @ReactMethod
|
||||||
|
+ override fun read(path: String, length: Double, position: Double, promise: Promise) {
|
||||||
|
+ ioScope.launch {
|
||||||
|
+ try {
|
||||||
|
+ val data = openForReading(path).use {
|
||||||
|
+ it.skip(position.toLong())
|
||||||
|
+ val byteArray = ByteArray(length.toInt())
|
||||||
|
+ it.read(byteArray)
|
||||||
|
+ byteArray
|
||||||
|
+ }
|
||||||
|
+ val writableArray: WritableArray = WritableNativeArray()
|
||||||
|
+ for (byte in data) {
|
||||||
|
+ writableArray.pushInt(byte.toInt() and 0xFF)
|
||||||
|
+ }
|
||||||
|
+ promise.resolve(writableArray)
|
||||||
|
+ } catch (e: Throwable) {
|
||||||
|
+ promise.reject(e)
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
@ReactMethod
|
||||||
|
override fun stat(path: String, promise: Promise) {
|
||||||
|
ioScope.launch {
|
||||||
|
diff --git a/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt b/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt
|
||||||
|
index 736324b..c223276 100644
|
||||||
|
--- a/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt
|
||||||
|
+++ b/node_modules/react-native-file-access/android/src/oldarch/FileAccessSpec.kt
|
||||||
|
@@ -30,6 +30,7 @@ abstract class FileAccessSpec internal constructor(context: ReactApplicationCont
|
||||||
|
abstract fun mkdir(path: String, promise: Promise)
|
||||||
|
abstract fun mv(source: String, target: String, promise: Promise)
|
||||||
|
abstract fun readFile(path: String, encoding: String, promise: Promise)
|
||||||
|
+ abstract fun read(path: String, length: Double, position: Double, promise: Promise)
|
||||||
|
abstract fun stat(path: String, promise: Promise)
|
||||||
|
abstract fun statDir(path: String, promise: Promise)
|
||||||
|
abstract fun unlink(path: String, promise: Promise)
|
||||||
|
diff --git a/node_modules/react-native-file-access/lib/commonjs/index.js b/node_modules/react-native-file-access/lib/commonjs/index.js
|
||||||
|
index 88f1c2c..20eb70b 100644
|
||||||
|
--- a/node_modules/react-native-file-access/lib/commonjs/index.js
|
||||||
|
+++ b/node_modules/react-native-file-access/lib/commonjs/index.js
|
||||||
|
@@ -209,6 +209,12 @@ const FileSystem = {
|
||||||
|
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
|
||||||
|
return FileAccessNative.readFile(path, encoding);
|
||||||
|
},
|
||||||
|
+ /**
|
||||||
|
+ * Read the content of a file as a byte array.
|
||||||
|
+ */
|
||||||
|
+ read(path, length, position) {
|
||||||
|
+ return FileAccessNative.read(path, length, position);
|
||||||
|
+ },
|
||||||
|
/**
|
||||||
|
* Read file metadata.
|
||||||
|
*/
|
||||||
|
diff --git a/node_modules/react-native-file-access/lib/module/index.js b/node_modules/react-native-file-access/lib/module/index.js
|
||||||
|
index 0581920..22c37d3 100644
|
||||||
|
--- a/node_modules/react-native-file-access/lib/module/index.js
|
||||||
|
+++ b/node_modules/react-native-file-access/lib/module/index.js
|
||||||
|
@@ -198,6 +198,12 @@ export const FileSystem = {
|
||||||
|
let encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8';
|
||||||
|
return FileAccessNative.readFile(path, encoding);
|
||||||
|
},
|
||||||
|
+ /**
|
||||||
|
+ * Read the content of a file as a byte array.
|
||||||
|
+ */
|
||||||
|
+ read(path, length, position) {
|
||||||
|
+ return FileAccessNative.read(path, length, position);
|
||||||
|
+ },
|
||||||
|
/**
|
||||||
|
* Read file metadata.
|
||||||
|
*/
|
||||||
|
diff --git a/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts b/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts
|
||||||
|
index 0c58874..ed84081 100644
|
||||||
|
--- a/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts
|
||||||
|
+++ b/node_modules/react-native-file-access/lib/typescript/NativeFileAccess.d.ts
|
||||||
|
@@ -63,6 +63,7 @@ export interface Spec extends TurboModule {
|
||||||
|
mkdir(path: string): Promise<string>;
|
||||||
|
mv(source: string, target: string): Promise<void>;
|
||||||
|
readFile(path: string, encoding: string): Promise<string>;
|
||||||
|
+ read(path: string, length: number, position: number): Promise<number[]>;
|
||||||
|
stat(path: string): Promise<FileStat>;
|
||||||
|
statDir(path: string): Promise<FileStat[]>;
|
||||||
|
unlink(path: string): Promise<void>;
|
||||||
|
diff --git a/node_modules/react-native-file-access/lib/typescript/index.d.ts b/node_modules/react-native-file-access/lib/typescript/index.d.ts
|
||||||
|
index 5433d53..12854ca 100644
|
||||||
|
--- a/node_modules/react-native-file-access/lib/typescript/index.d.ts
|
||||||
|
+++ b/node_modules/react-native-file-access/lib/typescript/index.d.ts
|
||||||
|
@@ -84,6 +84,10 @@ export declare const FileSystem: {
|
||||||
|
* Read the content of a file.
|
||||||
|
*/
|
||||||
|
readFile(path: string, encoding?: Encoding): Promise<string>;
|
||||||
|
+ /**
|
||||||
|
+ * Read the content of a file as a byte array.
|
||||||
|
+ */
|
||||||
|
+ read(path: string, length?: number, position?: number): Promise<number[]>;
|
||||||
|
/**
|
||||||
|
* Read file metadata.
|
||||||
|
*/
|
||||||
|
diff --git a/node_modules/react-native-file-access/src/NativeFileAccess.ts b/node_modules/react-native-file-access/src/NativeFileAccess.ts
|
||||||
|
index b3a7baa..affd76c 100644
|
||||||
|
--- a/node_modules/react-native-file-access/src/NativeFileAccess.ts
|
||||||
|
+++ b/node_modules/react-native-file-access/src/NativeFileAccess.ts
|
||||||
|
@@ -71,6 +71,7 @@ export interface Spec extends TurboModule {
|
||||||
|
mkdir(path: string): Promise<string>;
|
||||||
|
mv(source: string, target: string): Promise<void>;
|
||||||
|
readFile(path: string, encoding: string): Promise<string>;
|
||||||
|
+ read(path: string, length: number, position: number): Promise<number[]>;
|
||||||
|
stat(path: string): Promise<FileStat>;
|
||||||
|
statDir(path: string): Promise<FileStat[]>;
|
||||||
|
unlink(path: string): Promise<void>;
|
||||||
|
diff --git a/node_modules/react-native-file-access/src/index.ts b/node_modules/react-native-file-access/src/index.ts
|
||||||
|
index 1b38d45..5c9fd5e 100644
|
||||||
|
--- a/node_modules/react-native-file-access/src/index.ts
|
||||||
|
+++ b/node_modules/react-native-file-access/src/index.ts
|
||||||
|
@@ -31,7 +31,6 @@ const LINKING_ERROR =
|
||||||
|
'- You rebuilt the app after installing the package\n' +
|
||||||
|
'- You are not using Expo Go\n';
|
||||||
|
|
||||||
|
-// @ts-expect-error
|
||||||
|
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
||||||
|
|
||||||
|
const FileAccessModule = isTurboModuleEnabled
|
||||||
|
@@ -275,6 +274,13 @@ export const FileSystem = {
|
||||||
|
return FileAccessNative.readFile(path, encoding);
|
||||||
|
},
|
||||||
|
|
||||||
|
+ /**
|
||||||
|
+ * Read the content of a file as a byte array.
|
||||||
|
+ */
|
||||||
|
+ read(path: string, length: number = 1000, position: number = 0) {
|
||||||
|
+ return FileAccessNative.read(path, length, position);
|
||||||
|
+ },
|
||||||
|
+
|
||||||
|
/**
|
||||||
|
* Read file metadata.
|
||||||
|
*/
|
@@ -9,14 +9,9 @@ import {
|
|||||||
useKeyboard,
|
useKeyboard,
|
||||||
} from '@react-native-community/hooks';
|
} from '@react-native-community/hooks';
|
||||||
import Clipboard from '@react-native-clipboard/clipboard';
|
import Clipboard from '@react-native-clipboard/clipboard';
|
||||||
import { documentPickerResponseToAddMemeFile, ROUTE } from '../types';
|
|
||||||
import {
|
|
||||||
allowedMimeTypes,
|
|
||||||
getFilenameFromUri,
|
|
||||||
guessMimeType,
|
|
||||||
noOp,
|
|
||||||
} from '../utilities';
|
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { documentPickerResponseToAddMemeFile, ROUTE } from '../types';
|
||||||
|
import { allowedMimeTypes, getFilenameFromUri, noOp } from '../utilities';
|
||||||
import { setSnackbarMessage } from '../state';
|
import { setSnackbarMessage } from '../state';
|
||||||
|
|
||||||
const floatingActionButtonStyles = StyleSheet.create({
|
const floatingActionButtonStyles = StyleSheet.create({
|
||||||
@@ -59,17 +54,11 @@ const FloatingActionButton = ({ visible = true }: { visible?: boolean }) => {
|
|||||||
dispatch(setSnackbarMessage('Clipboard does not contain a URI.'));
|
dispatch(setSnackbarMessage('Clipboard does not contain a URI.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const mimeType = guessMimeType(uri);
|
|
||||||
if (!mimeType) {
|
|
||||||
dispatch(setSnackbarMessage('Unsupported MIME type.'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
navigate(ROUTE.ADD_MEME, {
|
navigate(ROUTE.ADD_MEME, {
|
||||||
files: [
|
files: [
|
||||||
{
|
{
|
||||||
uri: uri,
|
uri: uri,
|
||||||
filename: getFilenameFromUri(uri),
|
filename: getFilenameFromUri(uri),
|
||||||
type: mimeType,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@@ -1,15 +1,8 @@
|
|||||||
export {
|
|
||||||
MemesList,
|
|
||||||
MemeEditor,
|
|
||||||
MemeFail,
|
|
||||||
MemesHeader,
|
|
||||||
MemeTagSelector,
|
|
||||||
MemeViewItem,
|
|
||||||
} from './memes';
|
|
||||||
export { TagChip, TagEditor, TagPreview, TagRow, TagsHeader } from './tags';
|
|
||||||
export { default as AnimatedImage } from './animatedImage';
|
export { default as AnimatedImage } from './animatedImage';
|
||||||
export { default as FloatingActionButton } from './floatingActionButton';
|
export { default as FloatingActionButton } from './floatingActionButton';
|
||||||
export { default as HideableBottomNavigationBar } from './hideableBottomNavigationBar';
|
export { default as HideableBottomNavigationBar } from './hideableBottomNavigationBar';
|
||||||
export { default as HideableHeader } from './hideableHeader';
|
export { default as HideableHeader } from './hideableHeader';
|
||||||
export { default as LoadingView } from './loadingView';
|
export { default as LoadingView } from './loadingView';
|
||||||
export { default as storageLocationChangeDialog } from './storageLocationChangeDialog';
|
export { default as MemeFail } from './memeFail';
|
||||||
|
export { default as TagChip } from './tagChip';
|
||||||
|
export { default as TextOverlay } from './textOverlay';
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { ComponentProps } from 'react';
|
||||||
import { ActivityIndicator, StyleSheet, View } from 'react-native';
|
import { ActivityIndicator, StyleSheet, View } from 'react-native';
|
||||||
import { useTheme } from 'react-native-paper';
|
import { useTheme } from 'react-native-paper';
|
||||||
|
|
||||||
@@ -10,12 +10,17 @@ const loadingViewStyles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const LoadingView = () => {
|
const LoadingView = ({ ...props }: ComponentProps<typeof View>) => {
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
style={[loadingViewStyles.view, { backgroundColor: colors.background }]}>
|
{...props}
|
||||||
|
style={[
|
||||||
|
props.style,
|
||||||
|
loadingViewStyles.view,
|
||||||
|
{ backgroundColor: colors.background },
|
||||||
|
]}>
|
||||||
<ActivityIndicator size="large" color={colors.primary} />
|
<ActivityIndicator size="large" color={colors.primary} />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
@@ -2,7 +2,7 @@ import React, { ComponentProps } from 'react';
|
|||||||
import { StyleSheet, View } from 'react-native';
|
import { StyleSheet, View } from 'react-native';
|
||||||
import { useTheme } from 'react-native-paper';
|
import { useTheme } from 'react-native-paper';
|
||||||
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
|
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
|
||||||
import { rgbToRgba } from '../../utilities';
|
import { rgbToRgba } from '../utilities';
|
||||||
|
|
||||||
const memeFailStyles = StyleSheet.create({
|
const memeFailStyles = StyleSheet.create({
|
||||||
view: {
|
view: {
|
@@ -1,6 +0,0 @@
|
|||||||
export { default as MemesList } from './memesList/memesList';
|
|
||||||
export { default as MemeEditor } from './memeEditor';
|
|
||||||
export { default as MemeFail } from './memeFail';
|
|
||||||
export { default as MemesHeader } from './memesHeader';
|
|
||||||
export { default as MemeTagSelector } from './memeTagSelector/memeTagSelector';
|
|
||||||
export { default as MemeViewItem } from './memeViewItem';
|
|
@@ -1,112 +0,0 @@
|
|||||||
import React, { useEffect } from 'react';
|
|
||||||
import { HelperText, Text, TextInput, useTheme } from 'react-native-paper';
|
|
||||||
import { Image } from 'react-native';
|
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
||||||
import { useImageDimensions } from '@react-native-community/hooks/lib/useImageDimensions';
|
|
||||||
import { MemeFail, MemeTagSelector, LoadingView } from '..';
|
|
||||||
import { Tag } from '../../database';
|
|
||||||
import { StringValidationResult, validateMemeTitle } from '../../utilities';
|
|
||||||
|
|
||||||
const memeEditorStyles = {
|
|
||||||
image: {
|
|
||||||
marginBottom: 15,
|
|
||||||
borderRadius: 5,
|
|
||||||
},
|
|
||||||
uri: {
|
|
||||||
marginBottom: 15,
|
|
||||||
marginHorizontal: 5,
|
|
||||||
},
|
|
||||||
memeTagSelector: {
|
|
||||||
marginBottom: 10,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
marginBottom: 10,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const MemeEditor = ({
|
|
||||||
memeUri,
|
|
||||||
memeFilename,
|
|
||||||
memeError,
|
|
||||||
setMemeError,
|
|
||||||
memeTitle,
|
|
||||||
setMemeTitle,
|
|
||||||
memeTags,
|
|
||||||
setMemeTags,
|
|
||||||
}: {
|
|
||||||
memeUri: string;
|
|
||||||
memeFilename?: string;
|
|
||||||
memeError: Error | undefined;
|
|
||||||
setMemeError: (error: Error | undefined) => void;
|
|
||||||
memeTitle: StringValidationResult;
|
|
||||||
setMemeTitle: (name: StringValidationResult) => void;
|
|
||||||
memeTags: Map<string, Tag>;
|
|
||||||
setMemeTags: (tags: Map<string, Tag>) => void;
|
|
||||||
}) => {
|
|
||||||
const { width } = useSafeAreaFrame();
|
|
||||||
const { colors } = useTheme();
|
|
||||||
|
|
||||||
const { dimensions, loading, error } = useImageDimensions({ uri: memeUri });
|
|
||||||
useEffect(() => setMemeError(error), [error, setMemeError]);
|
|
||||||
|
|
||||||
if (!memeError && (loading || !dimensions)) return <LoadingView />;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<TextInput
|
|
||||||
mode="outlined"
|
|
||||||
label="Title"
|
|
||||||
value={memeTitle.raw}
|
|
||||||
onChangeText={title => setMemeTitle(validateMemeTitle(title))}
|
|
||||||
error={!memeTitle.valid}
|
|
||||||
selectTextOnFocus
|
|
||||||
/>
|
|
||||||
<HelperText type="error" visible={!memeTitle.valid}>
|
|
||||||
{memeTitle.error}
|
|
||||||
</HelperText>
|
|
||||||
{memeError || !dimensions ? (
|
|
||||||
<MemeFail
|
|
||||||
style={[
|
|
||||||
{
|
|
||||||
width: width * 0.92,
|
|
||||||
height: width * 0.92,
|
|
||||||
},
|
|
||||||
memeEditorStyles.image,
|
|
||||||
]}
|
|
||||||
iconSize={50}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Image
|
|
||||||
source={{ uri: memeUri }}
|
|
||||||
style={[
|
|
||||||
{
|
|
||||||
width: width * 0.92,
|
|
||||||
height: Math.max(
|
|
||||||
Math.min(
|
|
||||||
((width * 0.92) / dimensions.width) * dimensions.height,
|
|
||||||
500,
|
|
||||||
),
|
|
||||||
100,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
memeEditorStyles.image,
|
|
||||||
]}
|
|
||||||
resizeMode="contain"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Text
|
|
||||||
variant="bodySmall"
|
|
||||||
style={[memeEditorStyles.uri, { color: colors.onSurfaceDisabled }]}
|
|
||||||
numberOfLines={1}>
|
|
||||||
{memeFilename}
|
|
||||||
</Text>
|
|
||||||
<MemeTagSelector
|
|
||||||
memeTags={memeTags}
|
|
||||||
setMemeTags={setMemeTags}
|
|
||||||
style={memeEditorStyles.memeTagSelector}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MemeEditor;
|
|
@@ -1,68 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { StyleSheet, View } from 'react-native';
|
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
|
||||||
import { useImageDimensions } from '@react-native-community/hooks';
|
|
||||||
import { AndroidScoped } from 'react-native-file-access';
|
|
||||||
import { useSelector } from 'react-redux';
|
|
||||||
import { Meme } from '../../database';
|
|
||||||
import { RootState } from '../../state';
|
|
||||||
import { AnimatedImage, LoadingView, MemeFail } from '..';
|
|
||||||
|
|
||||||
const memeViewItemStyles = StyleSheet.create({
|
|
||||||
view: {
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const MemeViewItem = ({ meme }: { meme: Meme }) => {
|
|
||||||
const { height, width } = useSafeAreaFrame();
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
const storageUri = useSelector(
|
|
||||||
(state: RootState) => state.settings.storageUri,
|
|
||||||
)!;
|
|
||||||
|
|
||||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
|
||||||
|
|
||||||
const { dimensions, loading, error } = useImageDimensions({ uri });
|
|
||||||
|
|
||||||
if (!error && (loading || !dimensions)) {
|
|
||||||
return (
|
|
||||||
<View style={{ width, height }}>
|
|
||||||
<LoadingView />
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={[{ width, height }, memeViewItemStyles.view]}>
|
|
||||||
{error || !dimensions ? (
|
|
||||||
<MemeFail
|
|
||||||
style={{
|
|
||||||
width: Math.min(width, height - 128),
|
|
||||||
height: Math.min(width, height - 128),
|
|
||||||
}}
|
|
||||||
iconSize={50}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<AnimatedImage
|
|
||||||
source={{ uri }}
|
|
||||||
style={
|
|
||||||
dimensions.aspectRatio > width / (height - 128)
|
|
||||||
? {
|
|
||||||
width,
|
|
||||||
height: width / (dimensions.width / dimensions.height),
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
width:
|
|
||||||
(height - 128) * (dimensions.width / dimensions.height),
|
|
||||||
height: height - 128,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MemeViewItem;
|
|
@@ -1,9 +1,9 @@
|
|||||||
import React, { ComponentProps, useMemo } from 'react';
|
import React, { ComponentProps, useMemo } from 'react';
|
||||||
import { getContrastColor } from '../../utilities';
|
|
||||||
import { Chip, useTheme } from 'react-native-paper';
|
import { Chip, useTheme } from 'react-native-paper';
|
||||||
import { Tag } from '../../database';
|
|
||||||
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
|
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
|
||||||
import { StyleSheet } from 'react-native';
|
import { StyleSheet } from 'react-native';
|
||||||
|
import { getContrastColor } from '../utilities';
|
||||||
|
import { Tag } from '../database';
|
||||||
|
|
||||||
const tagChipStyles = StyleSheet.create({
|
const tagChipStyles = StyleSheet.create({
|
||||||
chip: {
|
chip: {
|
@@ -1,5 +0,0 @@
|
|||||||
export { default as TagChip } from './tagChip';
|
|
||||||
export { default as TagEditor } from './tagEditor';
|
|
||||||
export { default as TagPreview } from './tagPreview';
|
|
||||||
export { default as TagRow } from './tagRow';
|
|
||||||
export { default as TagsHeader } from './tagsHeader';
|
|
@@ -1,66 +0,0 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
|
||||||
import { HelperText, TextInput } from 'react-native-paper';
|
|
||||||
import TagPreview from './tagPreview';
|
|
||||||
import {
|
|
||||||
StringValidationResult,
|
|
||||||
generateRandomColor,
|
|
||||||
validateColor,
|
|
||||||
validateTagName,
|
|
||||||
} from '../../utilities';
|
|
||||||
|
|
||||||
const TagEditor = ({
|
|
||||||
tagName,
|
|
||||||
setTagName,
|
|
||||||
tagColor,
|
|
||||||
setTagColor,
|
|
||||||
}: {
|
|
||||||
tagName: StringValidationResult;
|
|
||||||
setTagName: (name: StringValidationResult) => void;
|
|
||||||
tagColor: StringValidationResult;
|
|
||||||
setTagColor: (color: StringValidationResult) => void;
|
|
||||||
}) => {
|
|
||||||
const lastValidTagColor = useRef(tagColor.parsed);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (tagColor.valid) lastValidTagColor.current = tagColor.parsed;
|
|
||||||
}, [tagColor]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<TagPreview
|
|
||||||
name={tagName.parsed}
|
|
||||||
color={tagColor.valid ? tagColor.parsed : lastValidTagColor.current}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
mode="outlined"
|
|
||||||
label="Name"
|
|
||||||
value={tagName.raw}
|
|
||||||
onChangeText={name => setTagName(validateTagName(name))}
|
|
||||||
error={!tagName.valid}
|
|
||||||
selectTextOnFocus
|
|
||||||
/>
|
|
||||||
<HelperText type="error" visible={!tagName.valid}>
|
|
||||||
{tagName.error}
|
|
||||||
</HelperText>
|
|
||||||
<TextInput
|
|
||||||
mode="outlined"
|
|
||||||
label="Color"
|
|
||||||
value={tagColor.raw}
|
|
||||||
onChangeText={color => setTagColor(validateColor(color))}
|
|
||||||
error={!tagColor.valid}
|
|
||||||
autoCorrect={false}
|
|
||||||
right={
|
|
||||||
<TextInput.Icon
|
|
||||||
icon="palette"
|
|
||||||
onPress={() => setTagColor(validateColor(generateRandomColor()))}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<HelperText type="error" visible={!tagColor.valid}>
|
|
||||||
{tagColor.error}
|
|
||||||
</HelperText>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default TagEditor;
|
|
64
src/components/textOverlay.tsx
Normal file
64
src/components/textOverlay.tsx
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { TextBlock } from '@react-native-ml-kit/text-recognition';
|
||||||
|
import { TouchableRipple, useTheme } from 'react-native-paper';
|
||||||
|
import { StyleSheet } from 'react-native';
|
||||||
|
import { Dimensions } from '../types';
|
||||||
|
|
||||||
|
const textOverlayStyles = StyleSheet.create({
|
||||||
|
touchable: {
|
||||||
|
position: 'absolute',
|
||||||
|
borderWidth: 1,
|
||||||
|
zIndex: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const TextOverlay = ({
|
||||||
|
blocks,
|
||||||
|
onTextPress,
|
||||||
|
onTextLongPress,
|
||||||
|
imageDimensions,
|
||||||
|
frameDimensions,
|
||||||
|
}: {
|
||||||
|
blocks: TextBlock[];
|
||||||
|
onTextPress: (text: string) => void;
|
||||||
|
onTextLongPress: (text: string) => void;
|
||||||
|
imageDimensions: Dimensions;
|
||||||
|
frameDimensions: Dimensions;
|
||||||
|
}) => {
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const widthScale = frameDimensions.width / imageDimensions.width;
|
||||||
|
const heightScale = frameDimensions.height / imageDimensions.height;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{blocks.map(
|
||||||
|
(block, index) =>
|
||||||
|
block.frame && (
|
||||||
|
<TouchableRipple
|
||||||
|
key={index}
|
||||||
|
style={[
|
||||||
|
textOverlayStyles.touchable,
|
||||||
|
{
|
||||||
|
top: block.frame.top * heightScale - 5,
|
||||||
|
left: block.frame.left * widthScale - 5,
|
||||||
|
width: block.frame.width * widthScale + 10,
|
||||||
|
height: block.frame.height * heightScale + 10,
|
||||||
|
borderColor: colors.error,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
onPress={() =>
|
||||||
|
onTextPress(block.text.replaceAll('\n', ' ').trim())
|
||||||
|
}
|
||||||
|
onLongPress={() =>
|
||||||
|
onTextLongPress(block.text.replaceAll('\n', ' ').trim())
|
||||||
|
}>
|
||||||
|
<></>
|
||||||
|
</TouchableRipple>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TextOverlay;
|
@@ -1,5 +1,5 @@
|
|||||||
import { BSON, Object, ObjectSchema } from 'realm';
|
import { BSON, Object, ObjectSchema } from 'realm';
|
||||||
import { Tag } from './tag';
|
import { Tag } from '.';
|
||||||
|
|
||||||
enum MEME_TYPE {
|
enum MEME_TYPE {
|
||||||
IMAGE = 'Image',
|
IMAGE = 'Image',
|
||||||
@@ -17,11 +17,10 @@ const memeTypePlural = {
|
|||||||
[MEME_TYPE.TEXT]: 'Text',
|
[MEME_TYPE.TEXT]: 'Text',
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
class Meme extends Object<Meme> {
|
class Meme extends Object<Meme> {
|
||||||
id!: BSON.UUID;
|
id!: BSON.UUID;
|
||||||
type!: MEME_TYPE;
|
|
||||||
filename!: string;
|
filename!: string;
|
||||||
|
memeType!: MEME_TYPE;
|
||||||
mimeType!: string;
|
mimeType!: string;
|
||||||
size!: number;
|
size!: number;
|
||||||
title!: string;
|
title!: string;
|
||||||
@@ -38,8 +37,8 @@ class Meme extends Object<Meme> {
|
|||||||
primaryKey: 'id',
|
primaryKey: 'id',
|
||||||
properties: {
|
properties: {
|
||||||
id: { type: 'uuid', default: () => new BSON.UUID() },
|
id: { type: 'uuid', default: () => new BSON.UUID() },
|
||||||
type: { type: 'string', indexed: true },
|
|
||||||
filename: 'string',
|
filename: 'string',
|
||||||
|
memeType: { type: 'string', indexed: true },
|
||||||
mimeType: 'string',
|
mimeType: 'string',
|
||||||
size: 'int',
|
size: 'int',
|
||||||
title: 'string',
|
title: 'string',
|
||||||
|
@@ -1,8 +1,7 @@
|
|||||||
import { BSON, Object, ObjectSchema } from 'realm';
|
import { BSON, Object, ObjectSchema } from 'realm';
|
||||||
import { Meme } from './meme';
|
import { Meme } from '.';
|
||||||
import { generateRandomColor } from '../utilities';
|
import { generateRandomColor } from '../utilities';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
class Tag extends Object<Tag> {
|
class Tag extends Object<Tag> {
|
||||||
id!: BSON.UUID;
|
id!: BSON.UUID;
|
||||||
name!: string;
|
name!: string;
|
||||||
|
1
src/hooks/index.ts
Normal file
1
src/hooks/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default as useMemeDimensions } from './useMemeDimensions';
|
56
src/hooks/useMemeDimensions.ts
Normal file
56
src/hooks/useMemeDimensions.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { Image } from 'react-native';
|
||||||
|
import { Dimensions } from '../types';
|
||||||
|
|
||||||
|
const useMediaDimensions = (
|
||||||
|
uri?: string,
|
||||||
|
mimeType?: string,
|
||||||
|
onLoad?: (width: number, height: number, aspectRatio: number) => void,
|
||||||
|
onError?: (error: Error) => void,
|
||||||
|
) => {
|
||||||
|
const [dimensions, setDimensions] = useState<Dimensions | undefined>();
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<Error | undefined>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getDimensions = () => {
|
||||||
|
if (!uri || !mimeType) return;
|
||||||
|
|
||||||
|
const mimeStart = mimeType.split('/')[0];
|
||||||
|
|
||||||
|
switch (mimeStart) {
|
||||||
|
case 'image':
|
||||||
|
case 'video': {
|
||||||
|
Image.getSize(
|
||||||
|
uri,
|
||||||
|
(width, height) => {
|
||||||
|
const aspectRatio = width / height;
|
||||||
|
setDimensions({ width, height, aspectRatio });
|
||||||
|
setLoading(false);
|
||||||
|
onLoad?.(width, height, aspectRatio);
|
||||||
|
},
|
||||||
|
(errorIn: string) => {
|
||||||
|
const errorOut = new Error(errorIn);
|
||||||
|
setError(errorOut);
|
||||||
|
setLoading(false);
|
||||||
|
onError?.(errorOut);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
const errorOut = new Error(`Unknown mime type: ${mimeType}`);
|
||||||
|
setError(errorOut);
|
||||||
|
setLoading(false);
|
||||||
|
onError?.(errorOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getDimensions();
|
||||||
|
}, [mimeType, onError, onLoad, uri]);
|
||||||
|
|
||||||
|
return { dimensions, loading, error };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useMediaDimensions;
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useRef, useState } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { Appbar, Banner, Button, useTheme } from 'react-native-paper';
|
import { Appbar, Banner, Button, useTheme } from 'react-native-paper';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
import { ScrollView, View } from 'react-native';
|
import { ScrollView, View } from 'react-native';
|
||||||
@@ -14,16 +14,18 @@ import {
|
|||||||
documentPickerResponseToAddMemeFile,
|
documentPickerResponseToAddMemeFile,
|
||||||
ROUTE,
|
ROUTE,
|
||||||
RootStackParamList,
|
RootStackParamList,
|
||||||
} from '../../types';
|
StagingMeme,
|
||||||
import { Meme, Tag } from '../../database';
|
} from '../../../types';
|
||||||
import { RootState } from '../../state';
|
import { Meme, Tag } from '../../../database';
|
||||||
|
import { RootState } from '../../../state';
|
||||||
import {
|
import {
|
||||||
allowedMimeTypes,
|
allowedMimeTypes,
|
||||||
getMemeType,
|
getMemeTypeFromMimeType,
|
||||||
|
guessMimeType,
|
||||||
validateMemeTitle,
|
validateMemeTitle,
|
||||||
} from '../../utilities';
|
} from '../../../utilities';
|
||||||
import { MemeEditor } from '../../components';
|
import MemeEditor from './memeEditor';
|
||||||
import editorStyles from './editorStyles';
|
import editorStyles from '../editorStyles';
|
||||||
|
|
||||||
const AddMeme = ({
|
const AddMeme = ({
|
||||||
route,
|
route,
|
||||||
@@ -42,54 +44,83 @@ const AddMeme = ({
|
|||||||
const file = useRef(files.current[index]);
|
const file = useRef(files.current[index]);
|
||||||
const isLastFile = index === files.current.length - 1;
|
const isLastFile = index === files.current.length - 1;
|
||||||
|
|
||||||
const [memeUri, setMemeUri] = useState(file.current.uri);
|
|
||||||
const [memeFilename, setMemeFilename] = useState(file.current.filename);
|
|
||||||
const [memeError, setMemeError] = useState<Error>();
|
|
||||||
const [memeTitle, setMemeTitle] = useState(validateMemeTitle('New Meme'));
|
|
||||||
const [memeIsFavorite, setMemeIsFavorite] = useState(false);
|
|
||||||
const [memeTags, setMemeTags] = useState(new Map<string, Tag>());
|
|
||||||
|
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
const [isSavingAndAddingMore, setIsSavingAndAddingMore] = useState(false);
|
const [isSavingAndAddingMore, setIsSavingAndAddingMore] = useState(false);
|
||||||
|
|
||||||
const saveMeme = useCallback(async () => {
|
const [uri, setUri] = useState<string>();
|
||||||
const uuid = new BSON.UUID();
|
const [mimeType, setMimeType] = useState<string>();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const [loading, setLoading] = useState(true);
|
||||||
const mimeType = file.current.type!;
|
const [error, setError] = useState<Error>();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const [staging, setStaging] = useState<StagingMeme>();
|
||||||
const memeType = getMemeType(mimeType)!;
|
|
||||||
|
|
||||||
const fileExtension = extension(mimeType) as string;
|
const resetState = useCallback(async (newIndex: number) => {
|
||||||
if (!fileExtension) goBack();
|
setLoading(true);
|
||||||
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
setError(undefined);
|
||||||
|
|
||||||
|
setIndex(newIndex);
|
||||||
|
file.current = files.current[newIndex];
|
||||||
|
|
||||||
|
setUri(file.current.uri);
|
||||||
|
|
||||||
|
const guessedMimeType = await guessMimeType(file.current.uri);
|
||||||
|
if (!guessedMimeType) {
|
||||||
|
setError(
|
||||||
|
new Error('Could not determine MIME type or file is not supported.'),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setMimeType(guessedMimeType);
|
||||||
|
|
||||||
|
setStaging({
|
||||||
|
title: validateMemeTitle('New Meme'),
|
||||||
|
isFavorite: false,
|
||||||
|
tags: new Map<string, Tag>(),
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => void resetState(0), [resetState]);
|
||||||
|
|
||||||
|
const saveMeme = useCallback(async () => {
|
||||||
|
if (!mimeType || !staging) return;
|
||||||
|
const uuid = new BSON.UUID();
|
||||||
|
|
||||||
|
const memeType = getMemeTypeFromMimeType(mimeType);
|
||||||
|
if (!memeType) return;
|
||||||
|
|
||||||
|
const fileExtension = extension(mimeType);
|
||||||
|
if (!fileExtension) return;
|
||||||
|
|
||||||
const filename = `${uuid.toHexString()}-${Math.round(
|
const filename = `${uuid.toHexString()}-${Math.round(
|
||||||
Date.now() / 1000,
|
Date.now() / 1000,
|
||||||
)}.${fileExtension}`;
|
)}.${fileExtension}`;
|
||||||
const uri = AndroidScoped.appendPath(storageUri, filename);
|
const finalUri = AndroidScoped.appendPath(storageUri, filename);
|
||||||
|
|
||||||
await FileSystem.cp(file.current.uri, uri);
|
await FileSystem.cp(file.current.uri, finalUri);
|
||||||
const { size } = await FileSystem.stat(uri);
|
const { size } = await FileSystem.stat(finalUri);
|
||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
const meme: Meme | undefined = realm.create<Meme>(Meme.schema.name, {
|
const meme: Meme | undefined = realm.create<Meme>(Meme.schema.name, {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
type: memeType,
|
memeType,
|
||||||
filename,
|
filename,
|
||||||
mimeType,
|
mimeType: mimeType,
|
||||||
size,
|
size,
|
||||||
title: memeTitle.parsed,
|
title: staging.title.parsed,
|
||||||
isFavorite: memeIsFavorite,
|
isFavorite: staging.isFavorite,
|
||||||
tags: [...memeTags.values()],
|
tags: [...staging.tags.values()],
|
||||||
tagsLength: memeTags.size,
|
tagsLength: staging.tags.size,
|
||||||
});
|
});
|
||||||
|
|
||||||
memeTags.forEach(tag => {
|
staging.tags.forEach(tag => {
|
||||||
tag.dateModified = new Date();
|
tag.dateModified = new Date();
|
||||||
tag.memes.push(meme);
|
tag.memes.push(meme);
|
||||||
tag.memesLength = tag.memes.length;
|
tag.memesLength = tag.memes.length;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, [goBack, memeIsFavorite, memeTags, memeTitle.parsed, realm, storageUri]);
|
}, [mimeType, realm, staging, storageUri]);
|
||||||
|
|
||||||
const handleSave = useCallback(async () => {
|
const handleSave = useCallback(async () => {
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
@@ -101,37 +132,21 @@ const AddMeme = ({
|
|||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
await saveMeme();
|
await saveMeme();
|
||||||
setIsSaving(false);
|
setIsSaving(false);
|
||||||
|
await resetState(index + 1);
|
||||||
setIndex(index + 1);
|
}, [index, resetState, saveMeme]);
|
||||||
file.current = files.current[index + 1];
|
|
||||||
|
|
||||||
setMemeUri(file.current.uri);
|
|
||||||
setMemeFilename(file.current.filename);
|
|
||||||
setMemeTitle(validateMemeTitle('New Meme'));
|
|
||||||
setMemeIsFavorite(false);
|
|
||||||
setMemeTags(new Map<string, Tag>());
|
|
||||||
}, [index, saveMeme]);
|
|
||||||
|
|
||||||
const handleSaveAndAddMore = useCallback(async () => {
|
const handleSaveAndAddMore = useCallback(async () => {
|
||||||
setIsSavingAndAddingMore(true);
|
setIsSavingAndAddingMore(true);
|
||||||
await saveMeme();
|
await saveMeme();
|
||||||
setIsSavingAndAddingMore(false);
|
setIsSavingAndAddingMore(false);
|
||||||
|
|
||||||
setIndex(0);
|
|
||||||
const response = await pick({
|
const response = await pick({
|
||||||
type: allowedMimeTypes,
|
type: allowedMimeTypes,
|
||||||
allowMultiSelection: true,
|
allowMultiSelection: true,
|
||||||
}).catch(goBack);
|
}).catch(goBack);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
files.current = documentPickerResponseToAddMemeFile(response);
|
files.current = documentPickerResponseToAddMemeFile(response);
|
||||||
file.current = files.current[0];
|
await resetState(0);
|
||||||
|
}, [goBack, resetState, saveMeme]);
|
||||||
setMemeUri(file.current.uri);
|
|
||||||
setMemeFilename(file.current.filename);
|
|
||||||
setMemeTitle(validateMemeTitle('New Meme'));
|
|
||||||
setMemeIsFavorite(false);
|
|
||||||
setMemeTags(new Map<string, Tag>());
|
|
||||||
}, [goBack, saveMeme]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -139,20 +154,23 @@ const AddMeme = ({
|
|||||||
<Appbar.BackAction onPress={() => goBack()} />
|
<Appbar.BackAction onPress={() => goBack()} />
|
||||||
<Appbar.Content title={'Add Meme'} />
|
<Appbar.Content title={'Add Meme'} />
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon={memeIsFavorite ? 'heart' : 'heart-outline'}
|
icon={staging?.isFavorite ? 'heart' : 'heart-outline'}
|
||||||
onPress={() => setMemeIsFavorite(!memeIsFavorite)}
|
disabled={!staging}
|
||||||
|
onPress={() =>
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
setStaging({ ...staging!, isFavorite: !staging!.isFavorite })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Appbar.Header>
|
</Appbar.Header>
|
||||||
<Banner
|
<Banner
|
||||||
visible={!!memeError}
|
visible={!!error}
|
||||||
actions={[
|
actions={[
|
||||||
{
|
{
|
||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
onPress: goBack,
|
onPress: goBack,
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
The selected URI appears to be broken. This may have been caused by the
|
{error?.message}
|
||||||
file being corrupted or unsupported.
|
|
||||||
</Banner>
|
</Banner>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
contentContainerStyle={[
|
contentContainerStyle={[
|
||||||
@@ -164,14 +182,14 @@ const AddMeme = ({
|
|||||||
]}>
|
]}>
|
||||||
<View style={editorStyles.editorView}>
|
<View style={editorStyles.editorView}>
|
||||||
<MemeEditor
|
<MemeEditor
|
||||||
memeUri={memeUri}
|
uri={uri}
|
||||||
memeFilename={memeFilename}
|
mimeType={mimeType}
|
||||||
memeError={memeError}
|
loading={loading}
|
||||||
setMemeError={setMemeError}
|
setLoading={setLoading}
|
||||||
memeTitle={memeTitle}
|
error={error}
|
||||||
setMemeTitle={setMemeTitle}
|
setError={setError}
|
||||||
memeTags={memeTags}
|
staging={staging}
|
||||||
setMemeTags={setMemeTags}
|
setStaging={setStaging}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={editorStyles.saveButtonView}>
|
<View style={editorStyles.saveButtonView}>
|
||||||
@@ -180,10 +198,11 @@ const AddMeme = ({
|
|||||||
icon="plus"
|
icon="plus"
|
||||||
onPress={handleSaveAndAddMore}
|
onPress={handleSaveAndAddMore}
|
||||||
disabled={
|
disabled={
|
||||||
!memeTitle.valid ||
|
loading ||
|
||||||
|
!!error ||
|
||||||
isSaving ||
|
isSaving ||
|
||||||
isSavingAndAddingMore ||
|
isSavingAndAddingMore ||
|
||||||
!!memeError ||
|
!staging?.title.valid ||
|
||||||
!isLastFile
|
!isLastFile
|
||||||
}
|
}
|
||||||
loading={isSavingAndAddingMore}
|
loading={isSavingAndAddingMore}
|
||||||
@@ -195,10 +214,11 @@ const AddMeme = ({
|
|||||||
icon="floppy"
|
icon="floppy"
|
||||||
onPress={isLastFile ? handleSave : handleSaveAndNext}
|
onPress={isLastFile ? handleSave : handleSaveAndNext}
|
||||||
disabled={
|
disabled={
|
||||||
!memeTitle.valid ||
|
loading ||
|
||||||
|
!!error ||
|
||||||
isSaving ||
|
isSaving ||
|
||||||
isSavingAndAddingMore ||
|
isSavingAndAddingMore ||
|
||||||
!!memeError
|
!staging?.title.valid
|
||||||
}
|
}
|
||||||
loading={isSaving}
|
loading={isSaving}
|
||||||
style={editorStyles.saveButton}>
|
style={editorStyles.saveButton}>
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { ScrollView, View } from 'react-native';
|
import { ScrollView, View } from 'react-native';
|
||||||
import { Appbar, Banner, Button, useTheme } from 'react-native-paper';
|
import { Appbar, Banner, Button, useTheme } from 'react-native-paper';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
@@ -6,24 +6,24 @@ import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
|||||||
import { useObject, useRealm } from '@realm/react';
|
import { useObject, useRealm } from '@realm/react';
|
||||||
import { useDeviceOrientation } from '@react-native-community/hooks';
|
import { useDeviceOrientation } from '@react-native-community/hooks';
|
||||||
import { BSON } from 'realm';
|
import { BSON } from 'realm';
|
||||||
import { RootStackParamList, ROUTE } from '../../types';
|
|
||||||
import { pickSingle } from 'react-native-document-picker';
|
import { pickSingle } from 'react-native-document-picker';
|
||||||
import { AndroidScoped, FileSystem } from 'react-native-file-access';
|
import { AndroidScoped, FileSystem } from 'react-native-file-access';
|
||||||
import { extension } from 'react-native-mime-types';
|
import { extension } from 'react-native-mime-types';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { Tag, Meme } from '../../database';
|
import { RootStackParamList, ROUTE, StagingMeme } from '../../../types';
|
||||||
|
import { Meme } from '../../../database';
|
||||||
import {
|
import {
|
||||||
StringValidationResult,
|
|
||||||
allowedMimeTypes,
|
allowedMimeTypes,
|
||||||
deleteMeme,
|
deleteMeme,
|
||||||
favoriteMeme,
|
favoriteMeme,
|
||||||
getMemeType,
|
getMemeTypeFromMimeType,
|
||||||
|
guessMimeType,
|
||||||
noOp,
|
noOp,
|
||||||
validateMemeTitle,
|
validateMemeTitle,
|
||||||
} from '../../utilities';
|
} from '../../../utilities';
|
||||||
import { MemeEditor } from '../../components';
|
import { RootState } from '../../../state';
|
||||||
import editorStyles from './editorStyles';
|
import MemeEditor from './memeEditor';
|
||||||
import { RootState } from '../../state';
|
import editorStyles from '../editorStyles';
|
||||||
|
|
||||||
const EditMeme = ({
|
const EditMeme = ({
|
||||||
route,
|
route,
|
||||||
@@ -42,41 +42,67 @@ const EditMeme = ({
|
|||||||
Meme.schema.name,
|
Meme.schema.name,
|
||||||
BSON.UUID.createFromHexString(route.params.id),
|
BSON.UUID.createFromHexString(route.params.id),
|
||||||
)!;
|
)!;
|
||||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
|
||||||
|
|
||||||
const [hasChanges, setHasChanges] = useState(false);
|
|
||||||
|
|
||||||
const [memeError, setMemeError] = useState<Error>();
|
|
||||||
const [memeTitle, setMemeTitle] = useState(validateMemeTitle(meme.title));
|
|
||||||
const [memeTags, setMemeTags] = useState(
|
|
||||||
new Map<string, Tag>(meme.tags.map(tag => [tag.id.toHexString(), tag])),
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleMemeTitleChange = useCallback((title: StringValidationResult) => {
|
|
||||||
setMemeTitle(title);
|
|
||||||
setHasChanges(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleMemeTagsChange = useCallback((tags: Map<string, Tag>) => {
|
|
||||||
setMemeTags(tags);
|
|
||||||
setHasChanges(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const [isSaving, setIsSaving] = useState(false);
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
|
||||||
|
const [uri, setUri] = useState<string>();
|
||||||
|
const [mimeType, setMimeType] = useState<string>();
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState<Error>();
|
||||||
|
const [staging, setStaging] = useState<StagingMeme>();
|
||||||
|
const originalStaging = useRef<StagingMeme>();
|
||||||
|
|
||||||
|
const resetState = useCallback(
|
||||||
|
async (newUri: string) => {
|
||||||
|
setLoading(true);
|
||||||
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||||
|
setError(undefined);
|
||||||
|
|
||||||
|
setUri(newUri);
|
||||||
|
|
||||||
|
const guessedMimeType = await guessMimeType(newUri);
|
||||||
|
if (!guessedMimeType) {
|
||||||
|
setError(
|
||||||
|
new Error('Could not determine MIME type or file is not supported.'),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setMimeType(guessedMimeType);
|
||||||
|
|
||||||
|
const stagingMeme = {
|
||||||
|
title: validateMemeTitle(meme.title),
|
||||||
|
isFavorite: meme.isFavorite,
|
||||||
|
tags: new Map(meme.tags.map(tag => [tag.id.toHexString(), tag])),
|
||||||
|
};
|
||||||
|
|
||||||
|
setStaging(stagingMeme);
|
||||||
|
originalStaging.current = stagingMeme;
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
},
|
||||||
|
[meme.isFavorite, meme.tags, meme.title],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => void resetState(AndroidScoped.appendPath(storageUri, meme.filename)),
|
||||||
|
[meme.filename, resetState, storageUri],
|
||||||
|
);
|
||||||
|
|
||||||
const handleSave = useCallback(() => {
|
const handleSave = useCallback(() => {
|
||||||
|
if (!mimeType || !staging) return;
|
||||||
|
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
meme.tags.forEach(tag => {
|
meme.tags.forEach(tag => {
|
||||||
if (!memeTags.has(tag.id.toHexString())) {
|
if (!staging.tags.has(tag.id.toHexString())) {
|
||||||
tag.memes.slice(tag.memes.indexOf(meme), 1);
|
tag.memes.slice(tag.memes.indexOf(meme), 1);
|
||||||
tag.memesLength -= 1;
|
tag.memesLength -= 1;
|
||||||
tag.dateModified = new Date();
|
tag.dateModified = new Date();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
memeTags.forEach(tag => {
|
staging.tags.forEach(tag => {
|
||||||
if (!meme.tags.some(memeTag => memeTag.id.equals(tag.id))) {
|
if (!meme.tags.some(memeTag => memeTag.id.equals(tag.id))) {
|
||||||
tag.memes.push(meme);
|
tag.memes.push(meme);
|
||||||
tag.memesLength = tag.memes.length;
|
tag.memesLength = tag.memes.length;
|
||||||
@@ -84,15 +110,15 @@ const EditMeme = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
meme.title = memeTitle.parsed;
|
meme.title = staging.title.parsed;
|
||||||
// @ts-expect-error - Realm is a fuck
|
// @ts-expect-error - Realm is a fuck
|
||||||
meme.tags = [...memeTags.values()];
|
meme.tags = [...staging.tags.values()];
|
||||||
meme.tagsLength = memeTags.size;
|
meme.tagsLength = staging.tags.size;
|
||||||
meme.dateModified = new Date();
|
meme.dateModified = new Date();
|
||||||
});
|
});
|
||||||
|
|
||||||
goBack();
|
goBack();
|
||||||
}, [goBack, meme, memeTags, memeTitle.parsed, realm]);
|
}, [goBack, meme, mimeType, realm, staging]);
|
||||||
|
|
||||||
const handleDelete = useCallback(async () => {
|
const handleDelete = useCallback(async () => {
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
@@ -104,12 +130,18 @@ const EditMeme = ({
|
|||||||
const file = await pickSingle({ type: allowedMimeTypes }).catch(noOp);
|
const file = await pickSingle({ type: allowedMimeTypes }).catch(noOp);
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const guessedMimeType = await guessMimeType(file.uri, file.type);
|
||||||
const mimeType = file.type!;
|
if (!guessedMimeType) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
setError(
|
||||||
const memeType = getMemeType(mimeType)!;
|
new Error('Could not determine MIME type or file is not supported.'),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const fileExtension = extension(mimeType) as string;
|
const memeType = getMemeTypeFromMimeType(guessedMimeType);
|
||||||
|
if (!memeType) return;
|
||||||
|
|
||||||
|
const fileExtension = extension(guessedMimeType);
|
||||||
if (!fileExtension) return;
|
if (!fileExtension) return;
|
||||||
|
|
||||||
const filename = `${meme.id.toHexString()}-${
|
const filename = `${meme.id.toHexString()}-${
|
||||||
@@ -122,11 +154,13 @@ const EditMeme = ({
|
|||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
meme.filename = filename;
|
meme.filename = filename;
|
||||||
meme.type = memeType;
|
meme.memeType = memeType;
|
||||||
meme.mimeType = mimeType;
|
meme.mimeType = guessedMimeType;
|
||||||
meme.size = size;
|
meme.size = size;
|
||||||
});
|
});
|
||||||
}, [meme, realm, storageUri]);
|
|
||||||
|
void resetState(newUri);
|
||||||
|
}, [meme, realm, resetState, storageUri]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -140,7 +174,7 @@ const EditMeme = ({
|
|||||||
<Appbar.Action icon="delete" onPress={handleDelete} />
|
<Appbar.Action icon="delete" onPress={handleDelete} />
|
||||||
</Appbar.Header>
|
</Appbar.Header>
|
||||||
<Banner
|
<Banner
|
||||||
visible={!!memeError}
|
visible={!!error}
|
||||||
actions={[
|
actions={[
|
||||||
{
|
{
|
||||||
label: 'Fix URI',
|
label: 'Fix URI',
|
||||||
@@ -151,8 +185,7 @@ const EditMeme = ({
|
|||||||
onPress: handleDelete,
|
onPress: handleDelete,
|
||||||
},
|
},
|
||||||
]}>
|
]}>
|
||||||
The URI for this meme appears to be broken. This may have been caused by
|
{error?.message}
|
||||||
the file being moved or deleted.
|
|
||||||
</Banner>
|
</Banner>
|
||||||
<ScrollView
|
<ScrollView
|
||||||
contentContainerStyle={[
|
contentContainerStyle={[
|
||||||
@@ -164,14 +197,14 @@ const EditMeme = ({
|
|||||||
]}>
|
]}>
|
||||||
<View style={editorStyles.editorView}>
|
<View style={editorStyles.editorView}>
|
||||||
<MemeEditor
|
<MemeEditor
|
||||||
memeUri={uri}
|
uri={uri}
|
||||||
memeFilename={meme.filename}
|
mimeType={mimeType}
|
||||||
memeError={memeError}
|
loading={loading}
|
||||||
setMemeError={setMemeError}
|
setLoading={setLoading}
|
||||||
memeTitle={memeTitle}
|
error={error}
|
||||||
setMemeTitle={handleMemeTitleChange}
|
setError={setError}
|
||||||
memeTags={memeTags}
|
staging={staging}
|
||||||
setMemeTags={handleMemeTagsChange}
|
setStaging={setStaging}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={editorStyles.saveButtonView}>
|
<View style={editorStyles.saveButtonView}>
|
||||||
@@ -180,7 +213,11 @@ const EditMeme = ({
|
|||||||
icon="floppy"
|
icon="floppy"
|
||||||
onPress={handleSave}
|
onPress={handleSave}
|
||||||
disabled={
|
disabled={
|
||||||
!memeTitle.valid || !hasChanges || isSaving || !!memeError
|
loading ||
|
||||||
|
!!error ||
|
||||||
|
isSaving ||
|
||||||
|
!staging?.title.valid ||
|
||||||
|
originalStaging.current === staging
|
||||||
}
|
}
|
||||||
loading={isSaving}
|
loading={isSaving}
|
||||||
style={editorStyles.soloSaveButton}>
|
style={editorStyles.soloSaveButton}>
|
193
src/screens/editors/meme/memeEditor.tsx
Normal file
193
src/screens/editors/meme/memeEditor.tsx
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
import React, { useEffect, useMemo, useState } from 'react';
|
||||||
|
import { HelperText, Text, TextInput, useTheme } from 'react-native-paper';
|
||||||
|
import { Image, LayoutAnimation, View } from 'react-native';
|
||||||
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
|
import Video from 'react-native-video';
|
||||||
|
import { LoadingView, MemeFail, TextOverlay } from '../../../components';
|
||||||
|
import {
|
||||||
|
getFilenameFromUri,
|
||||||
|
getMemeTypeFromMimeType,
|
||||||
|
validateMemeTitle,
|
||||||
|
} from '../../../utilities';
|
||||||
|
import { StagingMeme } from '../../../types';
|
||||||
|
import { useMemeDimensions } from '../../../hooks';
|
||||||
|
import { MEME_TYPE } from '../../../database';
|
||||||
|
import MemeTagSelector from './memeTagSelector/memeTagSelector';
|
||||||
|
import TextRecognition, {
|
||||||
|
TextRecognitionResult,
|
||||||
|
} from '@react-native-ml-kit/text-recognition';
|
||||||
|
|
||||||
|
const memeEditorStyles = {
|
||||||
|
media: {
|
||||||
|
marginBottom: 15,
|
||||||
|
borderRadius: 5,
|
||||||
|
},
|
||||||
|
uri: {
|
||||||
|
marginBottom: 15,
|
||||||
|
marginHorizontal: 5,
|
||||||
|
},
|
||||||
|
memeTagSelector: {
|
||||||
|
marginBottom: 10,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
marginBottom: 10,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const MemeEditor = ({
|
||||||
|
uri,
|
||||||
|
mimeType,
|
||||||
|
loading,
|
||||||
|
setLoading,
|
||||||
|
error,
|
||||||
|
setError,
|
||||||
|
staging,
|
||||||
|
setStaging,
|
||||||
|
}: {
|
||||||
|
uri?: string;
|
||||||
|
mimeType?: string;
|
||||||
|
loading: boolean;
|
||||||
|
setLoading: (loading: boolean) => void;
|
||||||
|
error: Error | undefined;
|
||||||
|
setError: (error: Error | undefined) => void;
|
||||||
|
staging?: StagingMeme;
|
||||||
|
setStaging: (staging: StagingMeme) => void;
|
||||||
|
}) => {
|
||||||
|
const { width } = useSafeAreaFrame();
|
||||||
|
const { colors } = useTheme();
|
||||||
|
|
||||||
|
const { dimensions } = useMemeDimensions(
|
||||||
|
uri,
|
||||||
|
mimeType,
|
||||||
|
useMemo(
|
||||||
|
() => () => {
|
||||||
|
setLoading(false);
|
||||||
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
||||||
|
},
|
||||||
|
[setLoading],
|
||||||
|
),
|
||||||
|
useMemo(() => (errorIn: Error) => setError(errorIn), [setError]),
|
||||||
|
);
|
||||||
|
|
||||||
|
const [recognizedText, setRecognizedText] = useState<TextRecognitionResult>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!uri || !mimeType || !mimeType.startsWith('image')) return;
|
||||||
|
void TextRecognition.recognize(uri).then(setRecognizedText);
|
||||||
|
}, [mimeType, uri]);
|
||||||
|
|
||||||
|
const mediaComponent = useMemo(() => {
|
||||||
|
if (!mimeType || !dimensions || !staging) return <></>;
|
||||||
|
|
||||||
|
const dimensionStyles = {
|
||||||
|
width: width * 0.92,
|
||||||
|
height: Math.max(
|
||||||
|
Math.min((width * 0.92) / dimensions.aspectRatio, 500),
|
||||||
|
100,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const memeType = getMemeTypeFromMimeType(mimeType);
|
||||||
|
if (!memeType) return <></>;
|
||||||
|
|
||||||
|
switch (memeType) {
|
||||||
|
case MEME_TYPE.IMAGE:
|
||||||
|
case MEME_TYPE.GIF: {
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<Image
|
||||||
|
source={{ uri }}
|
||||||
|
style={[memeEditorStyles.media, dimensionStyles]}
|
||||||
|
resizeMode="contain"
|
||||||
|
/>
|
||||||
|
{recognizedText && (
|
||||||
|
<TextOverlay
|
||||||
|
blocks={recognizedText.blocks}
|
||||||
|
onTextPress={text =>
|
||||||
|
setStaging({
|
||||||
|
...staging,
|
||||||
|
title: validateMemeTitle(text),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
onTextLongPress={text =>
|
||||||
|
setStaging({
|
||||||
|
...staging,
|
||||||
|
title: validateMemeTitle(`${staging.title.parsed} ${text}`),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
imageDimensions={dimensions}
|
||||||
|
frameDimensions={{
|
||||||
|
...dimensionStyles,
|
||||||
|
aspectRatio: dimensionStyles.width / dimensionStyles.height,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case MEME_TYPE.VIDEO: {
|
||||||
|
return (
|
||||||
|
<Video
|
||||||
|
source={{ uri }}
|
||||||
|
style={[memeEditorStyles.media, dimensionStyles]}
|
||||||
|
resizeMode="contain"
|
||||||
|
controls
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [dimensions, mimeType, recognizedText, setStaging, staging, uri, width]);
|
||||||
|
|
||||||
|
if (!uri || !mimeType || !staging) return <LoadingView />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TextInput
|
||||||
|
mode="outlined"
|
||||||
|
label="Title"
|
||||||
|
value={staging.title.raw}
|
||||||
|
onChangeText={title =>
|
||||||
|
setStaging({ ...staging, title: validateMemeTitle(title) })
|
||||||
|
}
|
||||||
|
error={!staging.title.valid}
|
||||||
|
selectTextOnFocus
|
||||||
|
/>
|
||||||
|
<HelperText type="error" visible={!staging.title.valid}>
|
||||||
|
{staging.title.error}
|
||||||
|
</HelperText>
|
||||||
|
{error ? (
|
||||||
|
<MemeFail
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width: width * 0.92,
|
||||||
|
height: width * 0.92,
|
||||||
|
},
|
||||||
|
memeEditorStyles.media,
|
||||||
|
]}
|
||||||
|
iconSize={50}
|
||||||
|
/>
|
||||||
|
) : // eslint-disable-next-line unicorn/no-nested-ternary
|
||||||
|
loading || !dimensions ? (
|
||||||
|
<></>
|
||||||
|
) : (
|
||||||
|
mediaComponent
|
||||||
|
)}
|
||||||
|
<Text
|
||||||
|
variant="bodySmall"
|
||||||
|
style={[memeEditorStyles.uri, { color: colors.onSurfaceDisabled }]}
|
||||||
|
numberOfLines={1}>
|
||||||
|
{getFilenameFromUri(uri)}
|
||||||
|
</Text>
|
||||||
|
<MemeTagSelector
|
||||||
|
memeTags={staging.tags}
|
||||||
|
setMemeTags={tags => setStaging({ ...staging, tags })}
|
||||||
|
style={memeEditorStyles.memeTagSelector}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MemeEditor;
|
@@ -4,10 +4,10 @@ import { Chip, Modal, Portal, Searchbar, useTheme } from 'react-native-paper';
|
|||||||
import { LayoutAnimation, StyleSheet } from 'react-native';
|
import { LayoutAnimation, StyleSheet } from 'react-native';
|
||||||
import { FlashList } from '@shopify/flash-list';
|
import { FlashList } from '@shopify/flash-list';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { TAG_SORT, tagSortQuery } from '../../../types';
|
import { TAG_SORT, tagSortQuery } from '../../../../types';
|
||||||
import { TagChip } from '../../tags';
|
import { TagChip } from '../../../../components';
|
||||||
import { Tag } from '../../../database';
|
import { Tag } from '../../../../database';
|
||||||
import { validateTagName } from '../../../utilities';
|
import { validateTagName } from '../../../../utilities';
|
||||||
|
|
||||||
const memeTagSearchModalStyles = StyleSheet.create({
|
const memeTagSearchModalStyles = StyleSheet.create({
|
||||||
modal: {
|
modal: {
|
@@ -3,8 +3,8 @@ import { LayoutAnimation, StyleSheet, View } from 'react-native';
|
|||||||
import { Chip } from 'react-native-paper';
|
import { Chip } from 'react-native-paper';
|
||||||
import { FlashList } from '@shopify/flash-list';
|
import { FlashList } from '@shopify/flash-list';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { TagChip } from '../../tags';
|
import { TagChip } from '../../../../components';
|
||||||
import { Tag } from '../../../database';
|
import { Tag } from '../../../../database';
|
||||||
import MemeTagSearchModal from './memeTagSearchModal';
|
import MemeTagSearchModal from './memeTagSearchModal';
|
||||||
|
|
||||||
const memeTagSelectorStyles = StyleSheet.create({
|
const memeTagSelectorStyles = StyleSheet.create({
|
@@ -8,10 +8,11 @@ import {
|
|||||||
generateRandomColor,
|
generateRandomColor,
|
||||||
validateColor,
|
validateColor,
|
||||||
validateTagName,
|
validateTagName,
|
||||||
} from '../../utilities';
|
} from '../../../utilities';
|
||||||
import { Tag } from '../../database';
|
import { Tag } from '../../../database';
|
||||||
import { TagEditor } from '../../components';
|
import { StagingTag } from '../../../types';
|
||||||
import editorStyles from './editorStyles';
|
import TagEditor from './tagEditor';
|
||||||
|
import editorStyles from '../editorStyles';
|
||||||
|
|
||||||
const AddTag = () => {
|
const AddTag = () => {
|
||||||
const { goBack } = useNavigation();
|
const { goBack } = useNavigation();
|
||||||
@@ -19,10 +20,10 @@ const AddTag = () => {
|
|||||||
const orientation = useDeviceOrientation();
|
const orientation = useDeviceOrientation();
|
||||||
const realm = useRealm();
|
const realm = useRealm();
|
||||||
|
|
||||||
const [tagName, setTagName] = useState(validateTagName('newTag'));
|
const [staging, setStaging] = useState<StagingTag>({
|
||||||
const [tagColor, setTagColor] = useState(
|
name: validateTagName('newTag'),
|
||||||
validateColor(generateRandomColor()),
|
color: validateColor(generateRandomColor()),
|
||||||
);
|
});
|
||||||
|
|
||||||
// Although saving tags is instantaneous, we still want to show a loading
|
// Although saving tags is instantaneous, we still want to show a loading
|
||||||
// indicator to prevent the user from spamming the save button.
|
// indicator to prevent the user from spamming the save button.
|
||||||
@@ -31,11 +32,11 @@ const AddTag = () => {
|
|||||||
const saveTag = useCallback(() => {
|
const saveTag = useCallback(() => {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
realm.create(Tag.schema.name, {
|
realm.create(Tag.schema.name, {
|
||||||
name: tagName.parsed,
|
name: staging.name.parsed,
|
||||||
color: tagColor.parsed,
|
color: staging.color.parsed,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, [realm, tagColor.parsed, tagName.parsed]);
|
}, [realm, staging.color.parsed, staging.name.parsed]);
|
||||||
|
|
||||||
const handleSave = useCallback(() => {
|
const handleSave = useCallback(() => {
|
||||||
saveTag();
|
saveTag();
|
||||||
@@ -46,8 +47,10 @@ const AddTag = () => {
|
|||||||
setIsSavingAndAddingMore(true);
|
setIsSavingAndAddingMore(true);
|
||||||
saveTag();
|
saveTag();
|
||||||
setTimeout(() => setIsSavingAndAddingMore(false), 250);
|
setTimeout(() => setIsSavingAndAddingMore(false), 250);
|
||||||
setTagName(validateTagName('newTag'));
|
setStaging({
|
||||||
setTagColor(validateColor(generateRandomColor()));
|
name: validateTagName('newTag'),
|
||||||
|
color: validateColor(generateRandomColor()),
|
||||||
|
});
|
||||||
}, [saveTag]);
|
}, [saveTag]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -65,19 +68,14 @@ const AddTag = () => {
|
|||||||
{ backgroundColor: colors.background },
|
{ backgroundColor: colors.background },
|
||||||
]}>
|
]}>
|
||||||
<View style={editorStyles.editorView}>
|
<View style={editorStyles.editorView}>
|
||||||
<TagEditor
|
<TagEditor staging={staging} setStaging={setStaging} />
|
||||||
tagName={tagName}
|
|
||||||
setTagName={setTagName}
|
|
||||||
tagColor={tagColor}
|
|
||||||
setTagColor={setTagColor}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
<View style={editorStyles.saveButtonView}>
|
<View style={editorStyles.saveButtonView}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained-tonal"
|
mode="contained-tonal"
|
||||||
icon="plus"
|
icon="plus"
|
||||||
onPress={handleSaveAndAddMore}
|
onPress={handleSaveAndAddMore}
|
||||||
disabled={!tagName.valid || isSavingAndAddingMore}
|
disabled={!staging.name.valid || isSavingAndAddingMore}
|
||||||
loading={isSavingAndAddingMore}
|
loading={isSavingAndAddingMore}
|
||||||
style={editorStyles.saveAndAddButton}>
|
style={editorStyles.saveAndAddButton}>
|
||||||
Save & Add
|
Save & Add
|
||||||
@@ -86,7 +84,7 @@ const AddTag = () => {
|
|||||||
mode="contained"
|
mode="contained"
|
||||||
icon="floppy"
|
icon="floppy"
|
||||||
onPress={handleSave}
|
onPress={handleSave}
|
||||||
disabled={!tagName.valid || isSavingAndAddingMore}
|
disabled={!staging.name.valid || isSavingAndAddingMore}
|
||||||
style={editorStyles.saveButton}>
|
style={editorStyles.saveButton}>
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useState } from 'react';
|
import React, { useCallback, useRef, useState } from 'react';
|
||||||
import { ScrollView, View } from 'react-native';
|
import { ScrollView, View } from 'react-native';
|
||||||
import { Appbar, Button, useTheme } from 'react-native-paper';
|
import { Appbar, Button, useTheme } from 'react-native-paper';
|
||||||
import { useNavigation } from '@react-navigation/native';
|
import { useNavigation } from '@react-navigation/native';
|
||||||
@@ -6,16 +6,11 @@ import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
|||||||
import { BSON } from 'realm';
|
import { BSON } from 'realm';
|
||||||
import { useObject, useRealm } from '@realm/react';
|
import { useObject, useRealm } from '@realm/react';
|
||||||
import { useDeviceOrientation } from '@react-native-community/hooks';
|
import { useDeviceOrientation } from '@react-native-community/hooks';
|
||||||
import { TagEditor } from '../../components';
|
import { ROUTE, RootStackParamList, StagingTag } from '../../../types';
|
||||||
import { ROUTE, RootStackParamList } from '../../types';
|
import { Tag } from '../../../database';
|
||||||
import { Tag } from '../../database';
|
import { deleteTag, validateColor, validateTagName } from '../../../utilities';
|
||||||
import {
|
import TagEditor from './tagEditor';
|
||||||
StringValidationResult,
|
import editorStyles from '../editorStyles';
|
||||||
deleteTag,
|
|
||||||
validateColor,
|
|
||||||
validateTagName,
|
|
||||||
} from '../../utilities';
|
|
||||||
import editorStyles from './editorStyles';
|
|
||||||
|
|
||||||
const EditTag = ({
|
const EditTag = ({
|
||||||
route,
|
route,
|
||||||
@@ -31,29 +26,21 @@ const EditTag = ({
|
|||||||
BSON.UUID.createFromHexString(route.params.id),
|
BSON.UUID.createFromHexString(route.params.id),
|
||||||
)!;
|
)!;
|
||||||
|
|
||||||
const [hasChanges, setHasChanges] = useState(false);
|
const [staging, setStaging] = useState<StagingTag>({
|
||||||
const [tagName, setTagName] = useState(validateTagName(tag.name));
|
name: validateTagName(tag.name),
|
||||||
const [tagColor, setTagColor] = useState(validateColor(tag.color));
|
color: validateColor(tag.color),
|
||||||
|
});
|
||||||
const handleTagNameChange = useCallback((name: StringValidationResult) => {
|
const originalStaging = useRef<StagingTag>(staging);
|
||||||
setTagName(name);
|
|
||||||
setHasChanges(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleTagColorChange = useCallback((color: StringValidationResult) => {
|
|
||||||
setTagColor(color);
|
|
||||||
setHasChanges(true);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleSave = useCallback(() => {
|
const handleSave = useCallback(() => {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
tag.name = tagName.parsed;
|
tag.name = staging.name.parsed;
|
||||||
tag.color = tagColor.parsed;
|
tag.color = staging.color.parsed;
|
||||||
tag.dateModified = new Date();
|
tag.dateModified = new Date();
|
||||||
});
|
});
|
||||||
|
|
||||||
goBack();
|
goBack();
|
||||||
}, [goBack, realm, tag, tagColor.parsed, tagName.parsed]);
|
}, [goBack, realm, staging.color.parsed, staging.name.parsed, tag]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -78,19 +65,18 @@ const EditTag = ({
|
|||||||
]}
|
]}
|
||||||
nestedScrollEnabled>
|
nestedScrollEnabled>
|
||||||
<View style={editorStyles.editorView}>
|
<View style={editorStyles.editorView}>
|
||||||
<TagEditor
|
<TagEditor staging={staging} setStaging={setStaging} />
|
||||||
tagName={tagName}
|
|
||||||
setTagName={handleTagNameChange}
|
|
||||||
tagColor={tagColor}
|
|
||||||
setTagColor={handleTagColorChange}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
<View style={editorStyles.saveButtonView}>
|
<View style={editorStyles.saveButtonView}>
|
||||||
<Button
|
<Button
|
||||||
mode="contained"
|
mode="contained"
|
||||||
icon="floppy"
|
icon="floppy"
|
||||||
onPress={handleSave}
|
onPress={handleSave}
|
||||||
disabled={!tagName.valid || !tagColor.valid || !hasChanges}
|
disabled={
|
||||||
|
!staging.name.valid ||
|
||||||
|
!staging.color.valid ||
|
||||||
|
originalStaging.current === staging
|
||||||
|
}
|
||||||
style={editorStyles.soloSaveButton}>
|
style={editorStyles.soloSaveButton}>
|
||||||
Save
|
Save
|
||||||
</Button>
|
</Button>
|
73
src/screens/editors/tag/tagEditor.tsx
Normal file
73
src/screens/editors/tag/tagEditor.tsx
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react';
|
||||||
|
import { HelperText, TextInput } from 'react-native-paper';
|
||||||
|
import {
|
||||||
|
generateRandomColor,
|
||||||
|
validateColor,
|
||||||
|
validateTagName,
|
||||||
|
} from '../../../utilities';
|
||||||
|
import { StagingTag } from '../../../types';
|
||||||
|
import TagPreview from './tagPreview';
|
||||||
|
|
||||||
|
const TagEditor = ({
|
||||||
|
staging,
|
||||||
|
setStaging,
|
||||||
|
}: {
|
||||||
|
staging: StagingTag;
|
||||||
|
setStaging: (staging: StagingTag) => void;
|
||||||
|
}) => {
|
||||||
|
const lastValidColor = useRef(staging.color.parsed);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (staging.color.valid) lastValidColor.current = staging.color.parsed;
|
||||||
|
}, [staging.color.parsed, staging.color.valid]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TagPreview
|
||||||
|
name={staging.name.parsed}
|
||||||
|
color={
|
||||||
|
staging.color.valid ? staging.color.parsed : lastValidColor.current
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
mode="outlined"
|
||||||
|
label="Name"
|
||||||
|
value={staging.name.raw}
|
||||||
|
onChangeText={name =>
|
||||||
|
setStaging({ ...staging, name: validateTagName(name) })
|
||||||
|
}
|
||||||
|
error={!staging.name.valid}
|
||||||
|
selectTextOnFocus
|
||||||
|
/>
|
||||||
|
<HelperText type="error" visible={!staging.name.valid}>
|
||||||
|
{staging.name.error}
|
||||||
|
</HelperText>
|
||||||
|
<TextInput
|
||||||
|
mode="outlined"
|
||||||
|
label="Color"
|
||||||
|
value={staging.color.raw}
|
||||||
|
onChangeText={color =>
|
||||||
|
setStaging({ ...staging, color: validateColor(color) })
|
||||||
|
}
|
||||||
|
error={!staging.color.valid}
|
||||||
|
autoCorrect={false}
|
||||||
|
right={
|
||||||
|
<TextInput.Icon
|
||||||
|
icon="palette"
|
||||||
|
onPress={() =>
|
||||||
|
setStaging({
|
||||||
|
...staging,
|
||||||
|
color: validateColor(generateRandomColor()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<HelperText type="error" visible={!staging.color.valid}>
|
||||||
|
{staging.color.error}
|
||||||
|
</HelperText>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TagEditor;
|
@@ -2,7 +2,7 @@ import React, { useMemo } from 'react';
|
|||||||
import { StyleSheet, View } from 'react-native';
|
import { StyleSheet, View } from 'react-native';
|
||||||
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
|
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
|
||||||
import { Chip, useTheme } from 'react-native-paper';
|
import { Chip, useTheme } from 'react-native-paper';
|
||||||
import { getContrastColor } from '../../utilities';
|
import { getContrastColor } from '../../../utilities';
|
||||||
|
|
||||||
const tagPreviewStyles = StyleSheet.create({
|
const tagPreviewStyles = StyleSheet.create({
|
||||||
view: {
|
view: {
|
@@ -1,9 +1,9 @@
|
|||||||
export { default as AddMeme } from './editors/addMeme';
|
export { default as AddMeme } from './editors/meme/addMeme';
|
||||||
export { default as AddTag } from './editors/addTag';
|
export { default as AddTag } from './editors/tag/addTag';
|
||||||
export { default as EditMeme } from './editors/editMeme';
|
export { default as EditMeme } from './editors/meme/editMeme';
|
||||||
export { default as EditTag } from './editors/editTag';
|
export { default as EditTag } from './editors/tag/editTag';
|
||||||
export { default as Memes } from './memes';
|
export { default as Memes } from './memes/memes';
|
||||||
export { default as MemeView } from './memeView';
|
export { default as MemeView } from './memeView/memeView';
|
||||||
export { default as Settings } from './settings';
|
export { default as Settings } from './settings/settings';
|
||||||
export { default as Tags } from './tags';
|
export { default as Tags } from './tags/tags';
|
||||||
export { default as Welcome } from './welcome';
|
export { default as Welcome } from './welcome';
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
||||||
import { StyleSheet } from 'react-native';
|
import { StyleSheet } from 'react-native';
|
||||||
import { useQuery, useRealm } from '@realm/react';
|
import { useQuery, useRealm } from '@realm/react';
|
||||||
@@ -6,9 +6,15 @@ import { FlashList } from '@shopify/flash-list';
|
|||||||
import { Appbar, Portal, Snackbar } from 'react-native-paper';
|
import { Appbar, Portal, Snackbar } from 'react-native-paper';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { NavigationProp, useNavigation } from '@react-navigation/native';
|
import { NavigationProp, useNavigation } from '@react-navigation/native';
|
||||||
import { RootStackParamList, ROUTE } from '../types';
|
import { useSelector } from 'react-redux';
|
||||||
import { Meme } from '../database';
|
import {
|
||||||
import { MemeViewItem } from '../components';
|
memesSortQuery,
|
||||||
|
RootStackParamList,
|
||||||
|
ROUTE,
|
||||||
|
SORT_DIRECTION,
|
||||||
|
} from '../../types';
|
||||||
|
import { Meme } from '../../database';
|
||||||
|
import { LoadingView } from '../../components';
|
||||||
import {
|
import {
|
||||||
copyMeme,
|
copyMeme,
|
||||||
deleteMeme,
|
deleteMeme,
|
||||||
@@ -16,9 +22,9 @@ import {
|
|||||||
favoriteMeme,
|
favoriteMeme,
|
||||||
multipleIdQuery,
|
multipleIdQuery,
|
||||||
shareMeme,
|
shareMeme,
|
||||||
} from '../utilities';
|
} from '../../utilities';
|
||||||
import { useSelector } from 'react-redux';
|
import { RootState } from '../../state';
|
||||||
import { RootState } from '../state';
|
import MemeViewItem from './memeViewItem';
|
||||||
|
|
||||||
const memeViewStyles = StyleSheet.create({
|
const memeViewStyles = StyleSheet.create({
|
||||||
// eslint-disable-next-line react-native/no-color-literals
|
// eslint-disable-next-line react-native/no-color-literals
|
||||||
@@ -50,87 +56,113 @@ const MemeView = ({
|
|||||||
}: NativeStackScreenProps<RootStackParamList, ROUTE.MEME_VIEW>) => {
|
}: NativeStackScreenProps<RootStackParamList, ROUTE.MEME_VIEW>) => {
|
||||||
const { height, width } = useSafeAreaFrame();
|
const { height, width } = useSafeAreaFrame();
|
||||||
const navigation = useNavigation<NavigationProp<RootStackParamList>>();
|
const navigation = useNavigation<NavigationProp<RootStackParamList>>();
|
||||||
|
const sort = useSelector((state: RootState) => state.memes.sort);
|
||||||
|
const sortDirection = useSelector(
|
||||||
|
(state: RootState) => state.memes.sortDirection,
|
||||||
|
);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
const storageUri = useSelector(
|
const storageUri = useSelector(
|
||||||
(state: RootState) => state.settings.storageUri,
|
(state: RootState) => state.settings.storageUri,
|
||||||
)!;
|
)!;
|
||||||
const realm = useRealm();
|
const realm = useRealm();
|
||||||
|
|
||||||
const { ids } = route.params;
|
const [isBlocked, setIsBlocked] = useState(false);
|
||||||
const [index, setIndex] = useState(route.params.index);
|
|
||||||
|
|
||||||
const [snackbarMessage, setSnackbarMessage] = useState<string>();
|
const [snackbarMessage, setSnackbarMessage] = useState<string>();
|
||||||
|
|
||||||
const flashListRef = useRef<FlashList<Meme>>(null);
|
const flashListRef = useRef<FlashList<Meme>>(null);
|
||||||
|
|
||||||
|
const index = useRef(route.params.index);
|
||||||
const memes = useQuery<Meme>(Meme.schema.name, collectionIn => {
|
const memes = useQuery<Meme>(Meme.schema.name, collectionIn => {
|
||||||
return collectionIn.filtered(multipleIdQuery(ids));
|
return collectionIn
|
||||||
|
.filtered(multipleIdQuery(route.params.ids))
|
||||||
|
.sorted(
|
||||||
|
memesSortQuery(sort),
|
||||||
|
sortDirection === SORT_DIRECTION.DESCENDING,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (memes.length === 0) navigation.goBack();
|
||||||
|
if (index.current >= memes.length) {
|
||||||
|
index.current = memes.length - 1;
|
||||||
|
flashListRef.current?.scrollToIndex({ index: memes.length - 1 });
|
||||||
|
}
|
||||||
|
}, [index, memes.length, navigation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Appbar.Header style={memeViewStyles.header}>
|
<Appbar.Header style={memeViewStyles.header}>
|
||||||
<Appbar.BackAction onPress={() => navigation.goBack()} />
|
<Appbar.BackAction onPress={() => navigation.goBack()} />
|
||||||
<Appbar.Content title={memes[index].title} />
|
{/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */}
|
||||||
|
<Appbar.Content title={memes[index.current]?.title} />
|
||||||
</Appbar.Header>
|
</Appbar.Header>
|
||||||
<FlashList
|
<FlashList
|
||||||
ref={flashListRef}
|
ref={flashListRef}
|
||||||
key={height}
|
key={height}
|
||||||
data={memes}
|
data={memes}
|
||||||
initialScrollIndex={index}
|
initialScrollIndex={index.current}
|
||||||
onScroll={event => {
|
onScroll={event => {
|
||||||
const newIndex = Math.round(
|
const newIndex = Math.round(
|
||||||
event.nativeEvent.contentOffset.x /
|
event.nativeEvent.contentOffset.x /
|
||||||
event.nativeEvent.layoutMeasurement.width,
|
event.nativeEvent.layoutMeasurement.width,
|
||||||
);
|
);
|
||||||
if (newIndex !== index) setIndex(newIndex);
|
if (newIndex !== index.current) index.current = newIndex;
|
||||||
}}
|
}}
|
||||||
estimatedItemSize={width}
|
estimatedItemSize={width}
|
||||||
estimatedListSize={{ height, width }}
|
estimatedListSize={{ height, width }}
|
||||||
pagingEnabled
|
pagingEnabled
|
||||||
horizontal
|
horizontal
|
||||||
showsHorizontalScrollIndicator={false}
|
showsHorizontalScrollIndicator={false}
|
||||||
renderItem={({ item: meme }) => <MemeViewItem meme={meme} />}
|
renderItem={({ item }) =>
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
item ? (
|
||||||
|
<MemeViewItem meme={item} />
|
||||||
|
) : (
|
||||||
|
<LoadingView style={{ width, height }} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
scrollEnabled={!isBlocked}
|
||||||
/>
|
/>
|
||||||
<Appbar style={memeViewStyles.footer}>
|
<Appbar style={memeViewStyles.footer}>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon={memes[index].isFavorite ? 'heart' : 'heart-outline'}
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
onPress={() => favoriteMeme(realm, memes[index])}
|
icon={memes[index.current]?.isFavorite ? 'heart' : 'heart-outline'}
|
||||||
|
onPress={() => favoriteMeme(realm, memes[index.current])}
|
||||||
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="share"
|
icon="share"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
shareMeme(realm, storageUri, memes[index]).catch(() =>
|
shareMeme(realm, storageUri, memes[index.current]).catch(() =>
|
||||||
setSnackbarMessage('Failed to share meme!'),
|
setSnackbarMessage('Failed to share meme!'),
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="content-copy"
|
icon="content-copy"
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
await copyMeme(realm, storageUri, memes[index])
|
await copyMeme(realm, storageUri, memes[index.current])
|
||||||
.then(() => setSnackbarMessage('Meme copied!'))
|
.then(() => setSnackbarMessage('Meme copied!'))
|
||||||
.catch(() => setSnackbarMessage('Failed to copy meme!'));
|
.catch(() => setSnackbarMessage('Failed to copy meme!'));
|
||||||
}}
|
}}
|
||||||
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="pencil"
|
icon="pencil"
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
editMeme(navigation, memes[index]);
|
editMeme(navigation, memes[index.current]);
|
||||||
}}
|
}}
|
||||||
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
<Appbar.Action
|
<Appbar.Action
|
||||||
icon="delete"
|
icon="delete"
|
||||||
onPress={() => {
|
onPress={async () => {
|
||||||
void deleteMeme(realm, storageUri, memes[index]);
|
setIsBlocked(true);
|
||||||
if (index === memes.length - 1) {
|
await deleteMeme(realm, storageUri, memes[index.current]);
|
||||||
setIndex(index - 1);
|
setIsBlocked(false);
|
||||||
flashListRef.current?.scrollToIndex({
|
|
||||||
index: index - 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (memes.length === 1) navigation.goBack();
|
|
||||||
}}
|
}}
|
||||||
|
disabled={isBlocked}
|
||||||
/>
|
/>
|
||||||
</Appbar>
|
</Appbar>
|
||||||
<Portal>
|
<Portal>
|
78
src/screens/memeView/memeViewItem.tsx
Normal file
78
src/screens/memeView/memeViewItem.tsx
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import React, { useMemo } from 'react';
|
||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
|
import { AndroidScoped } from 'react-native-file-access';
|
||||||
|
import { useSelector } from 'react-redux';
|
||||||
|
import Video from 'react-native-video';
|
||||||
|
import { MEME_TYPE, Meme } from '../../database';
|
||||||
|
import { RootState } from '../../state';
|
||||||
|
import { AnimatedImage, LoadingView, MemeFail } from '../../components';
|
||||||
|
import { useMemeDimensions } from '../../hooks';
|
||||||
|
|
||||||
|
const memeViewItemStyles = StyleSheet.create({
|
||||||
|
view: {
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const MemeViewItem = ({ meme }: { meme: Meme }) => {
|
||||||
|
const { height, width } = useSafeAreaFrame();
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const storageUri = useSelector(
|
||||||
|
(state: RootState) => state.settings.storageUri,
|
||||||
|
)!;
|
||||||
|
|
||||||
|
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||||
|
|
||||||
|
const { dimensions, loading, error } = useMemeDimensions(uri, meme.mimeType);
|
||||||
|
|
||||||
|
const mediaComponent = useMemo(() => {
|
||||||
|
if (!dimensions) return <></>;
|
||||||
|
|
||||||
|
const dimensionStyles =
|
||||||
|
dimensions.aspectRatio > width / (height - 128)
|
||||||
|
? {
|
||||||
|
width,
|
||||||
|
height: width / (dimensions.width / dimensions.height),
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
width: (height - 128) * (dimensions.width / dimensions.height),
|
||||||
|
height: height - 128,
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (meme.memeType) {
|
||||||
|
case MEME_TYPE.IMAGE:
|
||||||
|
case MEME_TYPE.GIF: {
|
||||||
|
return <AnimatedImage source={{ uri }} style={dimensionStyles} />;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return (
|
||||||
|
<Video source={{ uri }} style={dimensionStyles} paused controls />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [dimensions, height, meme.memeType, uri, width]);
|
||||||
|
|
||||||
|
if (!error && (loading || !dimensions)) {
|
||||||
|
return <LoadingView style={{ width, height }} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={[{ width, height }, memeViewItemStyles.view]}>
|
||||||
|
{error || !dimensions ? (
|
||||||
|
<MemeFail
|
||||||
|
style={{
|
||||||
|
width: Math.min(width, height - 128),
|
||||||
|
height: Math.min(width, height - 128),
|
||||||
|
}}
|
||||||
|
iconSize={50}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
mediaComponent
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MemeViewItem;
|
@@ -17,11 +17,13 @@ import {
|
|||||||
useNavigation,
|
useNavigation,
|
||||||
} from '@react-navigation/native';
|
} from '@react-navigation/native';
|
||||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
||||||
import { ROUTE, SORT_DIRECTION, memesSortQuery } from '../types';
|
|
||||||
import { RootState, setNavVisible } from '../state';
|
|
||||||
import { Meme } from '../database';
|
|
||||||
import { HideableHeader, MemesHeader, MemesList } from '../components';
|
|
||||||
import { useDeviceOrientation } from '@react-native-community/hooks';
|
import { useDeviceOrientation } from '@react-native-community/hooks';
|
||||||
|
import { ROUTE, SORT_DIRECTION, memesSortQuery } from '../../types';
|
||||||
|
import { RootState, setNavVisible } from '../../state';
|
||||||
|
import { Meme } from '../../database';
|
||||||
|
import { HideableHeader } from '../../components';
|
||||||
|
import MemesHeader from './memesHeader';
|
||||||
|
import MemesList from './memesList/memesList';
|
||||||
|
|
||||||
const memesStyles = StyleSheet.create({
|
const memesStyles = StyleSheet.create({
|
||||||
listView: {
|
listView: {
|
||||||
@@ -80,7 +82,7 @@ const Memes = () => {
|
|||||||
.join(' OR ');
|
.join(' OR ');
|
||||||
|
|
||||||
if (favoritesOnly) collection = collection.filtered('isFavorite == true');
|
if (favoritesOnly) collection = collection.filtered('isFavorite == true');
|
||||||
if (filter) collection = collection.filtered('type == $0', filter);
|
if (filter) collection = collection.filtered('memeType == $0', filter);
|
||||||
if (tags && tagsQuery) {
|
if (tags && tagsQuery) {
|
||||||
collection = collection.filtered(tagsQuery, ...tags);
|
collection = collection.filtered(tagsQuery, ...tags);
|
||||||
}
|
}
|
||||||
@@ -98,7 +100,7 @@ const Memes = () => {
|
|||||||
[sort, sortDirection, favoritesOnly, filter, search],
|
[sort, sortDirection, favoritesOnly, filter, search],
|
||||||
);
|
);
|
||||||
|
|
||||||
const [scrollOffset, setScrollOffset] = useState(0);
|
const previousOffset = useRef(0);
|
||||||
|
|
||||||
const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||||
const currentOffset = event.nativeEvent.contentOffset.y;
|
const currentOffset = event.nativeEvent.contentOffset.y;
|
||||||
@@ -106,13 +108,13 @@ const Memes = () => {
|
|||||||
if (currentOffset <= 150) {
|
if (currentOffset <= 150) {
|
||||||
dispatch(setNavVisible(true));
|
dispatch(setNavVisible(true));
|
||||||
} else {
|
} else {
|
||||||
const diff = currentOffset - scrollOffset;
|
const diff = currentOffset - previousOffset.current;
|
||||||
if (Math.abs(diff) > 50) {
|
if (Math.abs(diff) > 35) {
|
||||||
dispatch(setNavVisible(diff < 0));
|
dispatch(setNavVisible(diff < 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setScrollOffset(currentOffset);
|
previousOffset.current = currentOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
const flashListRef = useRef<FlashList<Meme>>(null);
|
const flashListRef = useRef<FlashList<Meme>>(null);
|
||||||
@@ -120,7 +122,7 @@ const Memes = () => {
|
|||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
const handleBackPress = () => {
|
const handleBackPress = () => {
|
||||||
if (scrollOffset <= 0) return false;
|
if (previousOffset.current <= 0) return false;
|
||||||
flashListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
flashListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@@ -129,7 +131,7 @@ const Memes = () => {
|
|||||||
|
|
||||||
return () =>
|
return () =>
|
||||||
BackHandler.removeEventListener('hardwareBackPress', handleBackPress);
|
BackHandler.removeEventListener('hardwareBackPress', handleBackPress);
|
||||||
}, [scrollOffset]),
|
}, []),
|
||||||
);
|
);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
@@ -1,13 +1,13 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Image, TouchableHighlight } from 'react-native';
|
import { Image, TouchableHighlight } from 'react-native';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { useImageDimensions } from '@react-native-community/hooks';
|
|
||||||
import { AndroidScoped } from 'react-native-file-access';
|
import { AndroidScoped } from 'react-native-file-access';
|
||||||
import { Meme } from '../../../database';
|
import { MEME_TYPE, Meme } from '../../../database';
|
||||||
import { RootState } from '../../../state';
|
import { RootState } from '../../../state';
|
||||||
import { MemeFail } from '..';
|
import { MemeFail } from '../../../components';
|
||||||
import { getFontAwesome5IconSize } from '../../../utilities';
|
import { getFontAwesome5IconSize } from '../../../utilities';
|
||||||
|
import { useMemeDimensions } from '../../../hooks';
|
||||||
|
|
||||||
const MemesGridItem = ({
|
const MemesGridItem = ({
|
||||||
meme,
|
meme,
|
||||||
@@ -29,7 +29,32 @@ const MemesGridItem = ({
|
|||||||
|
|
||||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||||
|
|
||||||
const { dimensions, loading, error } = useImageDimensions({ uri });
|
const { dimensions, loading, error } = useMemeDimensions(uri, meme.mimeType);
|
||||||
|
|
||||||
|
const itemWidth = (width * 0.92 - 5) / gridColumns;
|
||||||
|
|
||||||
|
const mediaComponent = useMemo(() => {
|
||||||
|
switch (meme.memeType) {
|
||||||
|
case MEME_TYPE.IMAGE:
|
||||||
|
case MEME_TYPE.GIF:
|
||||||
|
case MEME_TYPE.VIDEO: {
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
source={{ uri }}
|
||||||
|
style={[
|
||||||
|
{
|
||||||
|
width: itemWidth,
|
||||||
|
height: itemWidth,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [itemWidth, meme.memeType, uri]);
|
||||||
|
|
||||||
if (!error && (loading || !dimensions)) return <></>;
|
if (!error && (loading || !dimensions)) return <></>;
|
||||||
|
|
||||||
@@ -44,15 +69,7 @@ const MemesGridItem = ({
|
|||||||
iconSize={getFontAwesome5IconSize(gridColumns)}
|
iconSize={getFontAwesome5IconSize(gridColumns)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Image
|
mediaComponent
|
||||||
source={{ uri }}
|
|
||||||
style={[
|
|
||||||
{
|
|
||||||
width: (width * 0.92 - 5) / gridColumns,
|
|
||||||
height: (width * 0.92 - 5) / gridColumns,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</TouchableHighlight>
|
</TouchableHighlight>
|
||||||
);
|
);
|
@@ -73,6 +73,7 @@ const MemesList = ({
|
|||||||
<MasonryFlashList
|
<MasonryFlashList
|
||||||
ref={flashListRef}
|
ref={flashListRef}
|
||||||
data={memes}
|
data={memes}
|
||||||
|
key={masonryColumns}
|
||||||
estimatedItemSize={getFlashListItemHeight(masonryColumns)}
|
estimatedItemSize={getFlashListItemHeight(masonryColumns)}
|
||||||
estimatedListSize={{
|
estimatedListSize={{
|
||||||
height,
|
height,
|
||||||
@@ -101,6 +102,7 @@ const MemesList = ({
|
|||||||
<FlashList
|
<FlashList
|
||||||
ref={flashListRef}
|
ref={flashListRef}
|
||||||
data={memes}
|
data={memes}
|
||||||
|
key={gridColumns}
|
||||||
estimatedItemSize={getFlashListItemHeight(gridColumns)}
|
estimatedItemSize={getFlashListItemHeight(gridColumns)}
|
||||||
estimatedListSize={{
|
estimatedListSize={{
|
||||||
height: height,
|
height: height,
|
@@ -1,13 +1,13 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Image, StyleSheet, View } from 'react-native';
|
import { Image, StyleSheet, View } from 'react-native';
|
||||||
import { Text, TouchableRipple } from 'react-native-paper';
|
import { Text, TouchableRipple } from 'react-native-paper';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { useImageDimensions } from '@react-native-community/hooks';
|
|
||||||
import { AndroidScoped } from 'react-native-file-access';
|
import { AndroidScoped } from 'react-native-file-access';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { Meme } from '../../../database';
|
import { MEME_TYPE, Meme } from '../../../database';
|
||||||
import { MemeFail } from '..';
|
import { MemeFail } from '../../../components';
|
||||||
import { RootState } from '../../../state';
|
import { RootState } from '../../../state';
|
||||||
|
import { useMemeDimensions } from '../../../hooks';
|
||||||
|
|
||||||
const memesListItemStyles = StyleSheet.create({
|
const memesListItemStyles = StyleSheet.create({
|
||||||
view: {
|
view: {
|
||||||
@@ -50,7 +50,20 @@ const MemesListItem = ({
|
|||||||
|
|
||||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||||
|
|
||||||
const { dimensions, loading, error } = useImageDimensions({ uri });
|
const { dimensions, loading, error } = useMemeDimensions(uri, meme.mimeType);
|
||||||
|
|
||||||
|
const mediaComponent = useMemo(() => {
|
||||||
|
switch (meme.memeType) {
|
||||||
|
case MEME_TYPE.IMAGE:
|
||||||
|
case MEME_TYPE.GIF:
|
||||||
|
case MEME_TYPE.VIDEO: {
|
||||||
|
return <Image source={{ uri }} style={[memesListItemStyles.image]} />;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [meme.memeType, uri]);
|
||||||
|
|
||||||
if (!error && (loading || !dimensions)) return <></>;
|
if (!error && (loading || !dimensions)) return <></>;
|
||||||
|
|
||||||
@@ -62,7 +75,7 @@ const MemesListItem = ({
|
|||||||
{error ? (
|
{error ? (
|
||||||
<MemeFail style={memesListItemStyles.image} />
|
<MemeFail style={memesListItemStyles.image} />
|
||||||
) : (
|
) : (
|
||||||
<Image source={{ uri }} style={memesListItemStyles.image} />
|
mediaComponent
|
||||||
)}
|
)}
|
||||||
<View
|
<View
|
||||||
style={[
|
style={[
|
@@ -1,13 +1,13 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { Image, StyleSheet, TouchableHighlight } from 'react-native';
|
import { Image, StyleSheet, TouchableHighlight } from 'react-native';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { AndroidScoped } from 'react-native-file-access';
|
import { AndroidScoped } from 'react-native-file-access';
|
||||||
import { useImageDimensions } from '@react-native-community/hooks';
|
import { MEME_TYPE, Meme } from '../../../database';
|
||||||
import { Meme } from '../../../database';
|
|
||||||
import { RootState } from '../../../state';
|
import { RootState } from '../../../state';
|
||||||
import { MemeFail } from '..';
|
import { MemeFail } from '../../../components';
|
||||||
import { getFontAwesome5IconSize } from '../../../utilities';
|
import { getFontAwesome5IconSize } from '../../../utilities';
|
||||||
|
import { useMemeDimensions } from '../../../hooks';
|
||||||
|
|
||||||
const memeMasonryItemStyles = StyleSheet.create({
|
const memeMasonryItemStyles = StyleSheet.create({
|
||||||
view: {
|
view: {
|
||||||
@@ -39,7 +39,35 @@ const MemesMasonryItem = ({
|
|||||||
|
|
||||||
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
const uri = AndroidScoped.appendPath(storageUri, meme.filename);
|
||||||
|
|
||||||
const { dimensions, loading, error } = useImageDimensions({ uri });
|
const { dimensions, loading, error } = useMemeDimensions(uri, meme.mimeType);
|
||||||
|
|
||||||
|
const itemWidth = (width * 0.92 - 5) / masonryColumns - 5;
|
||||||
|
const itemHeight =
|
||||||
|
((width * 0.92) / masonryColumns - 5) / (dimensions?.aspectRatio ?? 1);
|
||||||
|
|
||||||
|
const mediaComponent = useMemo(() => {
|
||||||
|
switch (meme.memeType) {
|
||||||
|
case MEME_TYPE.IMAGE:
|
||||||
|
case MEME_TYPE.GIF:
|
||||||
|
case MEME_TYPE.VIDEO: {
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
source={{ uri }}
|
||||||
|
style={[
|
||||||
|
memeMasonryItemStyles.image,
|
||||||
|
{
|
||||||
|
width: itemWidth,
|
||||||
|
height: itemHeight,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return <></>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [itemHeight, itemWidth, meme.memeType, uri]);
|
||||||
|
|
||||||
if (!error && (loading || !dimensions)) return <></>;
|
if (!error && (loading || !dimensions)) return <></>;
|
||||||
|
|
||||||
@@ -51,25 +79,12 @@ const MemesMasonryItem = ({
|
|||||||
<MemeFail
|
<MemeFail
|
||||||
style={[
|
style={[
|
||||||
memeMasonryItemStyles.image,
|
memeMasonryItemStyles.image,
|
||||||
{
|
{ width: itemWidth, height: itemHeight },
|
||||||
width: (width * 0.92) / masonryColumns - 5,
|
|
||||||
height: (width * 0.92) / masonryColumns - 5,
|
|
||||||
},
|
|
||||||
]}
|
]}
|
||||||
iconSize={getFontAwesome5IconSize(masonryColumns)}
|
iconSize={getFontAwesome5IconSize(masonryColumns)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Image
|
mediaComponent
|
||||||
source={{ uri }}
|
|
||||||
style={[
|
|
||||||
memeMasonryItemStyles.image,
|
|
||||||
{
|
|
||||||
width: (width * 0.92) / masonryColumns - 5,
|
|
||||||
height:
|
|
||||||
((width * 0.92) / masonryColumns - 5) / dimensions.aspectRatio,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</TouchableHighlight>
|
</TouchableHighlight>
|
||||||
);
|
);
|
@@ -11,6 +11,8 @@ import {
|
|||||||
} from 'react-native-paper';
|
} from 'react-native-paper';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import type {} from 'redux-thunk/extend-redux';
|
import type {} from 'redux-thunk/extend-redux';
|
||||||
|
import { useRealm } from '@realm/react';
|
||||||
|
import { FileSystem, FileStat } from 'react-native-file-access';
|
||||||
import {
|
import {
|
||||||
RootState,
|
RootState,
|
||||||
setAutofocusMemesSearch,
|
setAutofocusMemesSearch,
|
||||||
@@ -19,11 +21,9 @@ import {
|
|||||||
setMasonryColumns,
|
setMasonryColumns,
|
||||||
setNoMedia,
|
setNoMedia,
|
||||||
setSnackbarMessage,
|
setSnackbarMessage,
|
||||||
} from '../state';
|
} from '../../state';
|
||||||
import StorageLocationChangeDialog from '../components/storageLocationChangeDialog';
|
import { Meme } from '../../database';
|
||||||
import { useRealm } from '@realm/react';
|
import StorageLocationChangeDialog from './storageLocationChangeDialog';
|
||||||
import { FileSystem, FileStat } from 'react-native-file-access';
|
|
||||||
import { Meme } from '../database';
|
|
||||||
|
|
||||||
const settingsStyles = StyleSheet.create({
|
const settingsStyles = StyleSheet.create({
|
||||||
scrollView: {
|
scrollView: {
|
@@ -4,8 +4,8 @@ import { Dialog, ProgressBar, Text } from 'react-native-paper';
|
|||||||
import { openDocumentTree } from 'react-native-scoped-storage';
|
import { openDocumentTree } from 'react-native-scoped-storage';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { AndroidScoped, FileSystem } from 'react-native-file-access';
|
import { AndroidScoped, FileSystem } from 'react-native-file-access';
|
||||||
import { RootState, setStorageUri } from '../state';
|
import { RootState, setStorageUri } from '../../state';
|
||||||
import { clearPermissions, isPermissionForPath, noOp } from '../utilities';
|
import { clearPermissions, isPermissionForPath, noOp } from '../../utilities';
|
||||||
|
|
||||||
const storageLocationChangeDialogStyles = StyleSheet.create({
|
const storageLocationChangeDialogStyles = StyleSheet.create({
|
||||||
progressBar: {
|
progressBar: {
|
@@ -13,10 +13,12 @@ import { FlashList } from '@shopify/flash-list';
|
|||||||
import { useFocusEffect } from '@react-navigation/native';
|
import { useFocusEffect } from '@react-navigation/native';
|
||||||
import { useDeviceOrientation } from '@react-native-community/hooks';
|
import { useDeviceOrientation } from '@react-native-community/hooks';
|
||||||
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
import { useSafeAreaFrame } from 'react-native-safe-area-context';
|
||||||
import { HideableHeader, TagRow, TagsHeader } from '../components';
|
import { HideableHeader } from '../../components';
|
||||||
import { Tag } from '../database';
|
import { Tag } from '../../database';
|
||||||
import { RootState, setNavVisible } from '../state';
|
import { RootState, setNavVisible } from '../../state';
|
||||||
import { SORT_DIRECTION, tagSortQuery } from '../types';
|
import { SORT_DIRECTION, tagSortQuery } from '../../types';
|
||||||
|
import TagsHeader from './tagsHeader';
|
||||||
|
import TagRow from './tagsList/tagRow';
|
||||||
|
|
||||||
const tagsStyles = StyleSheet.create({
|
const tagsStyles = StyleSheet.create({
|
||||||
listView: {
|
listView: {
|
||||||
@@ -71,7 +73,7 @@ const Tags = () => {
|
|||||||
[search, sort, sortDirection],
|
[search, sort, sortDirection],
|
||||||
);
|
);
|
||||||
|
|
||||||
const [scrollOffset, setScrollOffset] = useState(0);
|
const previousOffset = useRef(0);
|
||||||
|
|
||||||
const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||||
const currentOffset = event.nativeEvent.contentOffset.y;
|
const currentOffset = event.nativeEvent.contentOffset.y;
|
||||||
@@ -79,11 +81,11 @@ const Tags = () => {
|
|||||||
if (currentOffset <= 150) {
|
if (currentOffset <= 150) {
|
||||||
dispatch(setNavVisible(true));
|
dispatch(setNavVisible(true));
|
||||||
} else {
|
} else {
|
||||||
const diff = currentOffset - scrollOffset;
|
const diff = currentOffset - previousOffset.current;
|
||||||
if (Math.abs(diff) > 50) dispatch(setNavVisible(diff < 0));
|
if (Math.abs(diff) > 50) dispatch(setNavVisible(diff < 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
setScrollOffset(currentOffset);
|
previousOffset.current = currentOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
const flashListRef = useRef<FlashList<Tag>>(null);
|
const flashListRef = useRef<FlashList<Tag>>(null);
|
||||||
@@ -91,7 +93,7 @@ const Tags = () => {
|
|||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
const handleBackPress = () => {
|
const handleBackPress = () => {
|
||||||
if (scrollOffset > 0) {
|
if (previousOffset.current > 0) {
|
||||||
flashListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
flashListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -102,7 +104,7 @@ const Tags = () => {
|
|||||||
|
|
||||||
return () =>
|
return () =>
|
||||||
BackHandler.removeEventListener('hardwareBackPress', handleBackPress);
|
BackHandler.removeEventListener('hardwareBackPress', handleBackPress);
|
||||||
}, [scrollOffset]),
|
}, []),
|
||||||
);
|
);
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
@@ -2,9 +2,9 @@ import React from 'react';
|
|||||||
import { StyleSheet, View } from 'react-native';
|
import { StyleSheet, View } from 'react-native';
|
||||||
import { TouchableRipple, Text } from 'react-native-paper';
|
import { TouchableRipple, Text } from 'react-native-paper';
|
||||||
import { useNavigation, NavigationProp } from '@react-navigation/native';
|
import { useNavigation, NavigationProp } from '@react-navigation/native';
|
||||||
import { Tag } from '../../database';
|
import { Tag } from '../../../database';
|
||||||
import { ROUTE, RootStackParamList } from '../../types';
|
import { ROUTE, RootStackParamList } from '../../../types';
|
||||||
import { TagChip } from '.';
|
import { TagChip } from '../../../components';
|
||||||
|
|
||||||
const tagRowStyles = StyleSheet.create({
|
const tagRowStyles = StyleSheet.create({
|
||||||
view: {
|
view: {
|
@@ -91,8 +91,7 @@ const updateNoMedia = createAsyncThunk(
|
|||||||
|
|
||||||
const validateSettings = createAsyncThunk(
|
const validateSettings = createAsyncThunk(
|
||||||
'settings/validateSettings',
|
'settings/validateSettings',
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
async (ignored, { dispatch, getState }) => {
|
||||||
async (_, { dispatch, getState }) => {
|
|
||||||
const state = getState() as RootState;
|
const state = getState() as RootState;
|
||||||
const { storageUri, noMedia } = state.settings;
|
const { storageUri, noMedia } = state.settings;
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
interface Dimensions {
|
interface Dimensions {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
aspectRatio: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { type Dimensions };
|
export { type Dimensions };
|
||||||
|
@@ -13,4 +13,5 @@ export {
|
|||||||
tagSortQuery,
|
tagSortQuery,
|
||||||
SORT_DIRECTION,
|
SORT_DIRECTION,
|
||||||
} from './sort';
|
} from './sort';
|
||||||
|
export { type StagingMeme, type StagingTag } from './staging';
|
||||||
export { VIEW } from './view';
|
export { VIEW } from './view';
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { DocumentPickerResponse } from 'react-native-document-picker';
|
import { DocumentPickerResponse } from 'react-native-document-picker';
|
||||||
import { getFilenameFromUri, guessMimeType } from '../utilities';
|
import { getFilenameFromUri } from '../utilities';
|
||||||
import { SharedItem } from './share';
|
import { SharedItem } from '.';
|
||||||
|
|
||||||
enum ROUTE {
|
enum ROUTE {
|
||||||
MAIN = 'Main',
|
MAIN = 'Main',
|
||||||
@@ -34,7 +34,7 @@ const documentPickerResponseToAddMemeFile = (
|
|||||||
return {
|
return {
|
||||||
uri,
|
uri,
|
||||||
filename: name ?? getFilenameFromUri(uri),
|
filename: name ?? getFilenameFromUri(uri),
|
||||||
type: type ?? guessMimeType(uri),
|
type: type ?? undefined,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -55,7 +55,7 @@ const sharedItemToAddMemeFile = (item: SharedItem): AddMemeFile[] => {
|
|||||||
return data.map(uri => ({
|
return data.map(uri => ({
|
||||||
uri,
|
uri,
|
||||||
filename: getFilenameFromUri(uri),
|
filename: getFilenameFromUri(uri),
|
||||||
type: guessMimeType(uri),
|
type: mimeType,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
15
src/types/staging.ts
Normal file
15
src/types/staging.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Tag } from '../database';
|
||||||
|
import { StringValidationResult } from '../utilities';
|
||||||
|
|
||||||
|
interface StagingMeme {
|
||||||
|
title: StringValidationResult;
|
||||||
|
isFavorite: boolean;
|
||||||
|
tags: Map<string, Tag>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StagingTag {
|
||||||
|
name: StringValidationResult;
|
||||||
|
color: StringValidationResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { type StagingMeme, type StagingTag };
|
@@ -1,8 +1,7 @@
|
|||||||
const packageName = 'com.karaolidis.terminallyonline';
|
const packageName = 'com.karaolidis.terminallyonline';
|
||||||
const appName = 'Terminally Online';
|
const appName = 'Terminally Online';
|
||||||
const fileProvider = 'com.karaolidis.terminallyonline.rnshare.fileprovider';
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
const noOp = () => {};
|
const noOp = () => {};
|
||||||
|
|
||||||
export { packageName, appName, fileProvider, noOp };
|
export { packageName, appName, noOp };
|
||||||
|
@@ -1,3 +1,6 @@
|
|||||||
|
import { FileSystem } from 'react-native-file-access';
|
||||||
|
import filetypemime from 'magic-bytes.js';
|
||||||
|
import { lookup } from 'react-native-mime-types';
|
||||||
import { MEME_TYPE } from '../database';
|
import { MEME_TYPE } from '../database';
|
||||||
|
|
||||||
const allowedImageMimeTypes = [
|
const allowedImageMimeTypes = [
|
||||||
@@ -10,42 +13,77 @@ const allowedImageMimeTypes = [
|
|||||||
|
|
||||||
const allowedGifMimeTypes = ['image/gif'];
|
const allowedGifMimeTypes = ['image/gif'];
|
||||||
|
|
||||||
const allowedMimeTypes = [...allowedImageMimeTypes, ...allowedGifMimeTypes];
|
const allowedVideoMimeTypes = [
|
||||||
|
'video/av01',
|
||||||
|
'video/3gpp',
|
||||||
|
'video/avc',
|
||||||
|
'video/hevc',
|
||||||
|
'video/x-matroska',
|
||||||
|
'video/mp2t',
|
||||||
|
'video/mp4',
|
||||||
|
'video/mp42',
|
||||||
|
'video/mp43',
|
||||||
|
'video/mp4v-es',
|
||||||
|
'video/mpeg',
|
||||||
|
'video/mpeg2',
|
||||||
|
'video/x-vnd.on2.vp8',
|
||||||
|
'video/x-vnd.on2.vp9',
|
||||||
|
'video/webm',
|
||||||
|
];
|
||||||
|
|
||||||
const getMemeType = (mimeType: string): MEME_TYPE | undefined => {
|
const allowedMimeTypes = [
|
||||||
switch (mimeType) {
|
...allowedImageMimeTypes,
|
||||||
case 'image/bmp':
|
...allowedGifMimeTypes,
|
||||||
case 'image/jpg':
|
...allowedVideoMimeTypes,
|
||||||
case 'image/jpeg':
|
];
|
||||||
case 'image/png':
|
|
||||||
case 'image/webp': {
|
const getMemeTypeFromMimeType = (mimeType: string): MEME_TYPE | undefined => {
|
||||||
|
if (!allowedMimeTypes.includes(mimeType)) return undefined;
|
||||||
|
|
||||||
|
const mimeStart = mimeType.split('/')[0];
|
||||||
|
|
||||||
|
switch (mimeStart) {
|
||||||
|
case 'image': {
|
||||||
|
if (mimeType === 'image/gif') return MEME_TYPE.GIF;
|
||||||
return MEME_TYPE.IMAGE;
|
return MEME_TYPE.IMAGE;
|
||||||
}
|
}
|
||||||
case 'image/gif': {
|
case 'video': {
|
||||||
return MEME_TYPE.GIF;
|
return MEME_TYPE.VIDEO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const guessMimeType = (filename: string): string | undefined => {
|
const guessMimeTypeFromExtension = (filename: string): string | undefined => {
|
||||||
const extension = filename.split('.').pop()?.toLowerCase();
|
const extension = filename.split('.').pop()?.toLowerCase();
|
||||||
switch (extension) {
|
if (!extension) return undefined;
|
||||||
case 'bmp': {
|
const guessedMimeType = lookup(extension);
|
||||||
return 'image/bmp';
|
if (!guessedMimeType) return undefined;
|
||||||
}
|
return guessedMimeType;
|
||||||
case 'jpg':
|
};
|
||||||
case 'jpeg': {
|
|
||||||
return 'image/jpeg';
|
const guessMimeTypeFromMagicBytes = async (
|
||||||
}
|
uri: string,
|
||||||
case 'png': {
|
): Promise<string | undefined> => {
|
||||||
return 'image/png';
|
const fileContent = await FileSystem.read(uri, 100);
|
||||||
}
|
const possibleMimeTypes = filetypemime(fileContent);
|
||||||
case 'webp': {
|
if (possibleMimeTypes.length === 0) return undefined;
|
||||||
return 'image/webp';
|
return possibleMimeTypes[0].mime;
|
||||||
}
|
};
|
||||||
case 'gif': {
|
|
||||||
return 'image/gif';
|
const guessMimeType = async (
|
||||||
}
|
uri: string,
|
||||||
|
hint?: string | null,
|
||||||
|
): Promise<string | undefined> => {
|
||||||
|
if (hint && allowedMimeTypes.includes(hint)) return hint;
|
||||||
|
|
||||||
|
let guessedMimeType = guessMimeTypeFromExtension(uri);
|
||||||
|
if (guessedMimeType && allowedMimeTypes.includes(guessedMimeType)) {
|
||||||
|
return guessedMimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
guessedMimeType = await guessMimeTypeFromMagicBytes(uri);
|
||||||
|
if (guessedMimeType && allowedMimeTypes.includes(guessedMimeType)) {
|
||||||
|
return guessedMimeType;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,6 +91,6 @@ export {
|
|||||||
allowedImageMimeTypes,
|
allowedImageMimeTypes,
|
||||||
allowedGifMimeTypes,
|
allowedGifMimeTypes,
|
||||||
allowedMimeTypes,
|
allowedMimeTypes,
|
||||||
getMemeType,
|
getMemeTypeFromMimeType,
|
||||||
guessMimeType,
|
guessMimeType,
|
||||||
};
|
};
|
||||||
|
@@ -7,14 +7,14 @@ export {
|
|||||||
rgbToRgba,
|
rgbToRgba,
|
||||||
generateRandomColor,
|
generateRandomColor,
|
||||||
} from './color';
|
} from './color';
|
||||||
export { packageName, appName, fileProvider, noOp } from './constants';
|
export { packageName, appName, noOp } from './constants';
|
||||||
export { multipleIdQuery } from './database';
|
export { multipleIdQuery } from './database';
|
||||||
export { getFlashListItemHeight, getFontAwesome5IconSize } from './dimensions';
|
export { getFlashListItemHeight, getFontAwesome5IconSize } from './dimensions';
|
||||||
export {
|
export {
|
||||||
allowedImageMimeTypes,
|
allowedImageMimeTypes,
|
||||||
allowedGifMimeTypes,
|
allowedGifMimeTypes,
|
||||||
allowedMimeTypes,
|
allowedMimeTypes,
|
||||||
getMemeType,
|
getMemeTypeFromMimeType,
|
||||||
guessMimeType,
|
guessMimeType,
|
||||||
} from './filesystem';
|
} from './filesystem';
|
||||||
export { getSortIcon, getViewIcon } from './icon';
|
export { getSortIcon, getViewIcon } from './icon';
|
||||||
|
@@ -4,7 +4,7 @@ import Share from 'react-native-share';
|
|||||||
import Clipboard from '@react-native-clipboard/clipboard';
|
import Clipboard from '@react-native-clipboard/clipboard';
|
||||||
import { Meme } from '../database';
|
import { Meme } from '../database';
|
||||||
import { ROUTE, RootStackParamList } from '../types';
|
import { ROUTE, RootStackParamList } from '../types';
|
||||||
import { noOp } from './constants';
|
import { noOp } from '.';
|
||||||
|
|
||||||
const favoriteMeme = (realm: Realm, meme: Meme) => {
|
const favoriteMeme = (realm: Realm, meme: Meme) => {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { isHexColor, isRgbColor } from './color';
|
import { isHexColor, isRgbColor } from '.';
|
||||||
|
|
||||||
interface StringValidationResult {
|
interface StringValidationResult {
|
||||||
valid: boolean;
|
valid: boolean;
|
||||||
|
Reference in New Issue
Block a user