release(desktop): Release v0.3.12 (#3115)
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
day: friday
|
||||
time: "12:00"
|
||||
timezone: Asia/Singapore
|
||||
target-branch: dev
|
||||
ignore:
|
||||
# Stuck by react 19
|
||||
- dependency-name: react
|
||||
versions: [">=19.0.0"]
|
||||
- dependency-name: react-dom
|
||||
versions: [">=19.0.0"]
|
||||
- dependency-name: "@types/react"
|
||||
versions: [">=19.0.0"]
|
||||
- dependency-name: "@types/react-dom"
|
||||
versions: [">=19.0.0"]
|
||||
|
||||
# Stuck by tailwindcss 4
|
||||
- dependency-name: tailwindcss
|
||||
versions: [">=4.0.0"]
|
||||
- dependency-name: daisyui
|
||||
versions: [">=5.0.0"]
|
||||
|
||||
# Stuck by expo 52
|
||||
- dependency-name: react-native
|
||||
versions: [">=0.78.0"]
|
||||
|
||||
# Stuck by unified 11
|
||||
- dependency-name: vfile
|
||||
versions: [">=6.0.0"]
|
||||
|
||||
# It's using export map and metro doesn't support it well
|
||||
- dependency-name: unist-util-visit-parents
|
||||
versions: [">=6.0.0"]
|
||||
open-pull-requests-limit: 100
|
||||
groups:
|
||||
minor:
|
||||
applies-to: version-updates
|
||||
update-types:
|
||||
- "minor"
|
||||
patch:
|
||||
applies-to: version-updates
|
||||
update-types:
|
||||
- "patch"
|
||||
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
target-branch: dev
|
||||
open-pull-requests-limit: 100
|
||||
@@ -5,10 +5,12 @@ on:
|
||||
branches: [dev, main]
|
||||
paths:
|
||||
- "apps/mobile/**"
|
||||
- "pnpm-lock.yaml"
|
||||
pull_request:
|
||||
branches: [dev, main]
|
||||
paths:
|
||||
- "apps/mobile/**"
|
||||
- "pnpm-lock.yaml"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
profile:
|
||||
@@ -29,7 +31,7 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 📦 Setup pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
run_install: true
|
||||
- name: 🏗 Setup Node.js
|
||||
|
||||
@@ -80,7 +80,6 @@ jobs:
|
||||
run: pnpm add -g appdmg
|
||||
|
||||
- name: Install the Apple certificate and provisioning profile
|
||||
if: runner.os == 'macOS'
|
||||
env:
|
||||
BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
|
||||
BUILD_CERTIFICATE_MAS_BASE64: ${{ secrets.BUILD_CERTIFICATE_MAS_BASE64 }}
|
||||
@@ -88,6 +87,7 @@ jobs:
|
||||
P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
|
||||
BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
|
||||
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
|
||||
if: runner.os == 'macOS' && env.BUILD_CERTIFICATE_BASE64 != '' && env.BUILD_CERTIFICATE_MAS_BASE64 != '' && env.BUILD_CERTIFICATE_MASPKG_BASE64 != '' && env.BUILD_PROVISION_PROFILE_BASE64 != ''
|
||||
run: |
|
||||
# create variables
|
||||
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
|
||||
@@ -203,7 +203,7 @@ jobs:
|
||||
- name: Generate artifact attestation
|
||||
if: github.ref_type == 'tag' || github.event.inputs.tag_version == 'true'
|
||||
continue-on-error: true
|
||||
uses: actions/attest-build-provenance@v1
|
||||
uses: actions/attest-build-provenance@v2
|
||||
with:
|
||||
subject-path: |
|
||||
apps/desktop/out/make/**/*.dmg
|
||||
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: PR Conventional Commit Validation
|
||||
uses: ytanikin/PRConventionalCommits@1.1.0
|
||||
uses: ytanikin/PRConventionalCommits@1.3.0
|
||||
with:
|
||||
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert","release"]'
|
||||
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert","release","build"]'
|
||||
add_label: false
|
||||
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: lizheming/github-translate-action@c55aac477e98562d4faed9f77c54ab8306ae6ebf
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -6,6 +6,7 @@ out
|
||||
.env
|
||||
.eslintcache
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
VITE_WEB_URL=http://localhost:5173
|
||||
VITE_API_URL=http://localhost:3000
|
||||
VITE_IMGPROXY_URL=http://localhost:2873
|
||||
VITE_SENTRY_DSN=
|
||||
VITE_BUILD_TYPE=production
|
||||
VITE_INBOXES_EMAIL=@follow.re
|
||||
VITE_OPENPANEL_CLIENT_ID=
|
||||
VITE_OPENPANEL_API_URL=
|
||||
|
||||
VITE_EDITOR=cursor
|
||||
@@ -0,0 +1,7 @@
|
||||
# What's new in v0.3.12
|
||||
|
||||
## New Features
|
||||
|
||||
## Improvements
|
||||
|
||||
## Bug Fixes
|
||||
+11
-11
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "Follow",
|
||||
"type": "module",
|
||||
"version": "0.3.11",
|
||||
"version": "0.3.12",
|
||||
"private": true,
|
||||
"description": "Follow everything in one place",
|
||||
"author": "Follow Team",
|
||||
@@ -52,36 +52,36 @@
|
||||
"@follow/shared": "workspace:*",
|
||||
"@follow/utils": "workspace:*",
|
||||
"@pengx17/electron-forge-maker-appimage": "1.2.1",
|
||||
"@sentry/vite-plugin": "3.1.2",
|
||||
"@sentry/vite-plugin": "3.2.2",
|
||||
"@types/html-minifier-terser": "7.0.2",
|
||||
"@types/js-yaml": "4.0.9",
|
||||
"@types/react-google-recaptcha": "2.1.9",
|
||||
"@vitejs/plugin-legacy": "6.0.1",
|
||||
"@vitejs/plugin-legacy": "6.0.2",
|
||||
"@vitejs/plugin-react": "4.3.4",
|
||||
"autoprefixer": "10.4.20",
|
||||
"autoprefixer": "10.4.21",
|
||||
"bufferutil": "4.0.9",
|
||||
"cssnano": "7.0.6",
|
||||
"dotenv": "16.4.7",
|
||||
"drizzle-orm": "0.39.3",
|
||||
"electron": "34.2.0",
|
||||
"drizzle-orm": "0.40.0",
|
||||
"electron": "35.0.1",
|
||||
"electron-devtools-installer": "4.0.0",
|
||||
"electron-packager-languages": "0.6.0",
|
||||
"electron-vite": "3.0.0",
|
||||
"fake-indexeddb": "6.0.0",
|
||||
"happy-dom": "17.1.1",
|
||||
"hono": "4.7.2",
|
||||
"happy-dom": "17.4.4",
|
||||
"hono": "4.7.4",
|
||||
"html-minifier-terser": "7.2.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"nbump": "2.0.7",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"tar": "7.4.3",
|
||||
"tsup": "8.3.6",
|
||||
"unplugin-ast": "0.14.0",
|
||||
"tsup": "8.4.0",
|
||||
"unplugin-ast": "0.14.3",
|
||||
"utf-8-validate": "6.0.5"
|
||||
},
|
||||
"productName": "Follow",
|
||||
"mainHash": "ad983e722aa04bc9a5fc38a6978cd3740c6cfcc3e7e0adecf09f0d6955c63ad6",
|
||||
"mainHash": "03d744e78f7b1eedc24f83c05939b1faaa07b3b5ff15cfc6242594c74c726637",
|
||||
"bump": {
|
||||
"before": [
|
||||
"git pull --rebase",
|
||||
|
||||
@@ -29,15 +29,15 @@
|
||||
"@follow/shared": "workspace:*",
|
||||
"@follow/utils": "workspace:*",
|
||||
"@openpanel/web": "1.0.1",
|
||||
"@sentry/electron": "5.11.0",
|
||||
"@sentry/electron": "6.1.0",
|
||||
"builder-util-runtime": "9.2.10",
|
||||
"cookie-es": "1.2.2",
|
||||
"cookie-es": "2.0.0",
|
||||
"electron-context-menu": "4.0.5",
|
||||
"electron-log": "5.3.0",
|
||||
"electron-log": "5.3.2",
|
||||
"electron-squirrel-startup": "1.0.1",
|
||||
"electron-store": "10.0.1",
|
||||
"electron-updater": "6.3.9",
|
||||
"es-toolkit": "1.32.0",
|
||||
"es-toolkit": "1.33.0",
|
||||
"fast-folder-size": "2.4.0",
|
||||
"font-list": "1.5.1",
|
||||
"i18next": "24.2.2",
|
||||
@@ -52,11 +52,12 @@
|
||||
"vscode-languagedetection": "npm:@vscode/vscode-languagedetection@1.0.22"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@follow/models": "workspace:*",
|
||||
"@follow/types": "workspace:*",
|
||||
"@types/js-yaml": "4.0.9",
|
||||
"@types/node": "22.13.4",
|
||||
"electron": "34.2.0",
|
||||
"@types/node": "22.13.10",
|
||||
"electron": "35.0.1",
|
||||
"electron-devtools-installer": "4.0.0",
|
||||
"hono": "4.7.2"
|
||||
"hono": "4.7.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { fileURLToPath, pathToFileURL } from "node:url"
|
||||
|
||||
import { isMacOS, isWindows } from "./env"
|
||||
|
||||
@@ -19,3 +19,7 @@ export const getTrayIconPath = () => {
|
||||
}
|
||||
return getIconPath()
|
||||
}
|
||||
|
||||
export const filePathToAppUrl = (filePath: string) => {
|
||||
return `app://follow.is${pathToFileURL(filePath).pathname}`
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@ if (squirrelStartup) {
|
||||
app.quit()
|
||||
}
|
||||
|
||||
const buildSafeHeaders = createBuildSafeHeaders(env.VITE_WEB_URL, [
|
||||
env.VITE_OPENPANEL_API_URL || "",
|
||||
IMAGE_PROXY_URL,
|
||||
env.VITE_API_URL,
|
||||
])
|
||||
|
||||
function bootstrap() {
|
||||
initializeAppStage0()
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
@@ -92,6 +98,15 @@ function bootstrap() {
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId(`re.${APP_PROTOCOL}`)
|
||||
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
details.requestHeaders = buildSafeHeaders({
|
||||
url: details.url,
|
||||
headers: details.requestHeaders,
|
||||
})
|
||||
|
||||
callback({ cancel: false, requestHeaders: details.requestHeaders })
|
||||
})
|
||||
|
||||
mainWindow = createMainWindow()
|
||||
|
||||
// restore cookies
|
||||
@@ -120,21 +135,6 @@ function bootstrap() {
|
||||
registerUpdater()
|
||||
registerAppTray()
|
||||
|
||||
const buildSafeHeaders = createBuildSafeHeaders(env.VITE_WEB_URL, [
|
||||
env.VITE_OPENPANEL_API_URL || "",
|
||||
IMAGE_PROXY_URL,
|
||||
env.VITE_API_URL,
|
||||
])
|
||||
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
details.requestHeaders = buildSafeHeaders({
|
||||
url: details.url,
|
||||
headers: details.requestHeaders,
|
||||
})
|
||||
|
||||
callback({ cancel: false, requestHeaders: details.requestHeaders })
|
||||
})
|
||||
|
||||
// handle session cookie when sign in with email in electron
|
||||
session.defaultSession.webRequest.onHeadersReceived(
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { User } from "@auth/core/types"
|
||||
import type { Credentials } from "@eneris/push-receiver/dist/types"
|
||||
import type { UserModel } from "@follow/models"
|
||||
|
||||
import { logger } from "~/logger"
|
||||
|
||||
@@ -12,8 +12,8 @@ export const getBetterAuthSessionCookie = () => store.get(BetterAuthKey)
|
||||
export const cleanBetterAuthSessionCookie = () => store.set(BetterAuthKey, null)
|
||||
|
||||
const UserKey = "user"
|
||||
export const setUser = (user: User) => store.set(UserKey, JSON.stringify(user))
|
||||
export const getUser = (): User | null => {
|
||||
export const setUser = (user: UserModel) => store.set(UserKey, JSON.stringify(user))
|
||||
export const getUser = (): UserModel | null => {
|
||||
const user = store.get(UserKey)
|
||||
return user ? JSON.parse(user) : null
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { env } from "@follow/shared/env.desktop"
|
||||
import { app, BrowserWindow, clipboard, dialog, shell } from "electron"
|
||||
|
||||
import { BETTER_AUTH_COOKIE_NAME_SESSION_TOKEN } from "~/constants/app"
|
||||
import { filePathToAppUrl } from "~/helper"
|
||||
import { registerMenuAndContextMenu } from "~/init"
|
||||
import { clearAllData, getCacheSize } from "~/lib/cleaner"
|
||||
import { store, StoreKey } from "~/lib/store"
|
||||
@@ -210,7 +211,7 @@ export const appRoute = {
|
||||
|
||||
getAppPath: t.procedure.action(async () => app.getAppPath()),
|
||||
resolveAppAsarPath: t.procedure.input<string>().action(async ({ input }) => {
|
||||
return path.resolve(app.getAppPath(), input)
|
||||
return filePathToAppUrl(path.resolve(app.getAppPath(), input))
|
||||
}),
|
||||
|
||||
switchAppLocale: t.procedure.input<string>().action(async ({ input }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { User } from "@auth/core/types"
|
||||
import type { UserModel } from "@follow/models"
|
||||
|
||||
import { setUser } from "../lib/user"
|
||||
import { t } from "./_instance"
|
||||
@@ -6,7 +6,7 @@ import { t } from "./_instance"
|
||||
export const trackerRoute = {
|
||||
trackerIdentify: t.procedure
|
||||
.input<{
|
||||
user: User
|
||||
user: UserModel
|
||||
}>()
|
||||
.action(async ({ input }) => {
|
||||
const { user } = input
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from "node:path"
|
||||
import { fileURLToPath, pathToFileURL } from "node:url"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
import { is } from "@electron-toolkit/utils"
|
||||
import { APP_PROTOCOL } from "@follow/shared"
|
||||
@@ -10,7 +10,7 @@ import type { Event } from "electron/main"
|
||||
|
||||
import { START_IN_TRAY_ARGS } from "./constants/app"
|
||||
import { isDev, isMacOS, isWindows, isWindows11 } from "./env"
|
||||
import { getIconPath } from "./helper"
|
||||
import { filePathToAppUrl, getIconPath } from "./helper"
|
||||
import { t } from "./lib/i18n"
|
||||
import { store } from "./lib/store"
|
||||
import { getTrayConfig } from "./lib/tray"
|
||||
@@ -151,7 +151,7 @@ export function createWindow(
|
||||
logger.info("load dynamic render entry", dynamicRenderEntry)
|
||||
const appLoadFileEntry = dynamicRenderEntry || path.resolve(__dirname, "../renderer/index.html")
|
||||
|
||||
const appLoadEntry = `app://follow.is${pathToFileURL(appLoadFileEntry).pathname}${options?.extraPath || ""}`
|
||||
const appLoadEntry = `${filePathToAppUrl(appLoadFileEntry)}${options?.extraPath || ""}`
|
||||
|
||||
window.loadURL(appLoadEntry)
|
||||
logger.log("load URL", appLoadEntry)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"outDir": "dist",
|
||||
"types": ["electron-vite/node", "@follow/types/vite"],
|
||||
"types": ["electron-vite/node", "@follow/types/vite", "@follow/types/global"],
|
||||
"moduleResolution": "Bundler",
|
||||
"noImplicitReturns": false,
|
||||
"noUnusedLocals": false,
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
"@electron-toolkit/preload": "3.0.1",
|
||||
"@follow/electron-main": "workspace:*",
|
||||
"@follow/shared": "workspace:*",
|
||||
"@fontsource/sn-pro": "5.1.0",
|
||||
"@fontsource/sn-pro": "5.2.5",
|
||||
"@headlessui/react": "2.2.0",
|
||||
"@hookform/resolvers": "4.1.0",
|
||||
"@lottiefiles/dotlottie-react": "0.13.0",
|
||||
"@hookform/resolvers": "4.1.3",
|
||||
"@lottiefiles/dotlottie-react": "0.13.2",
|
||||
"@openpanel/web": "1.0.1",
|
||||
"@radix-ui/react-avatar": "1.1.3",
|
||||
"@radix-ui/react-context-menu": "2.2.6",
|
||||
@@ -32,13 +32,13 @@
|
||||
"@radix-ui/react-popover": "1.1.6",
|
||||
"@radix-ui/react-slider": "1.2.3",
|
||||
"@radix-ui/react-slot": "1.1.2",
|
||||
"@sentry/react": "9.1.0",
|
||||
"@shikijs/transformers": "3.0.0",
|
||||
"@tanstack/query-sync-storage-persister": "5.66.4",
|
||||
"@tanstack/react-query": "5.66.7",
|
||||
"@tanstack/react-query-devtools": "5.66.7",
|
||||
"@tanstack/react-query-persist-client": "5.66.7",
|
||||
"@tanstack/react-virtual": "3.13.0",
|
||||
"@sentry/react": "9.5.0",
|
||||
"@shikijs/transformers": "3.2.1",
|
||||
"@tanstack/query-sync-storage-persister": "5.67.3",
|
||||
"@tanstack/react-query": "5.67.3",
|
||||
"@tanstack/react-query-devtools": "5.67.3",
|
||||
"@tanstack/react-query-persist-client": "5.67.3",
|
||||
"@tanstack/react-virtual": "3.13.3",
|
||||
"@use-gesture/react": "10.3.1",
|
||||
"@welldone-software/why-did-you-render": "10.0.1",
|
||||
"@yornaath/batshit": "0.10.1",
|
||||
@@ -52,43 +52,43 @@
|
||||
"dnum": "2.14.0",
|
||||
"embla-carousel-react": "8.5.2",
|
||||
"embla-carousel-wheel-gestures": "8.0.1",
|
||||
"es-toolkit": "1.32.0",
|
||||
"firebase": "11.3.1",
|
||||
"es-toolkit": "1.33.0",
|
||||
"firebase": "11.4.0",
|
||||
"foxact": "0.2.44",
|
||||
"framer-motion": "12.4.7",
|
||||
"framer-motion": "12.5.0",
|
||||
"franc-min": "6.2.0",
|
||||
"fuse.js": "7.1.0",
|
||||
"hast-util-to-jsx-runtime": "2.3.2",
|
||||
"hast-util-to-jsx-runtime": "2.3.6",
|
||||
"hast-util-to-mdast": "10.1.2",
|
||||
"i18next": "24.2.2",
|
||||
"i18next-browser-languagedetector": "8.0.3",
|
||||
"i18next-browser-languagedetector": "8.0.4",
|
||||
"idb-keyval": "6.2.1",
|
||||
"immer": "10.1.1",
|
||||
"jotai": "2.12.1",
|
||||
"jotai": "2.12.2",
|
||||
"lethargy": "1.0.9",
|
||||
"masonic": "4.0.1",
|
||||
"mdast-util-gfm-table": "2.0.0",
|
||||
"mdast-util-to-markdown": "2.1.2",
|
||||
"nanoid": "5.1.0",
|
||||
"nanoid": "5.1.3",
|
||||
"ofetch": "1.4.1",
|
||||
"plain-shiki": "0.1.1",
|
||||
"re-resizable": "6.10.3",
|
||||
"plain-shiki": "0.2.0",
|
||||
"re-resizable": "6.11.2",
|
||||
"react-blurhash": "0.3.0",
|
||||
"react-fast-marquee": "1.6.5",
|
||||
"react-hook-form": "7.54.2",
|
||||
"react-hotkeys-hook": "4.6.1",
|
||||
"react-i18next": "15.4.1",
|
||||
"react-intersection-observer": "9.15.1",
|
||||
"react-intersection-observer": "9.16.0",
|
||||
"react-ios-pwa-prompt": "2.0.6",
|
||||
"react-qr-code": "2.0.15",
|
||||
"react-resizable-layout": "npm:@innei/react-resizable-layout@0.7.3-fork.1",
|
||||
"react-router": "7.2.0",
|
||||
"react-router": "7.3.0",
|
||||
"react-selecto": "1.26.3",
|
||||
"react-shadow": "20.6.0",
|
||||
"react-zoom-pan-pinch": "3.7.0",
|
||||
"shiki": "3.0.0",
|
||||
"sonner": "2.0.0",
|
||||
"tldts": "6.1.77",
|
||||
"shiki": "3.2.1",
|
||||
"sonner": "2.0.1",
|
||||
"tldts": "6.1.84",
|
||||
"use-context-selector": "2.0.0",
|
||||
"usehooks-ts": "3.1.1",
|
||||
"zod": "3.24.2",
|
||||
@@ -103,10 +103,10 @@
|
||||
"@follow/models": "workspace:*",
|
||||
"@follow/types": "workspace:*",
|
||||
"@follow/utils": "workspace:*",
|
||||
"@types/node": "22.13.4",
|
||||
"@types/node": "22.13.10",
|
||||
"@vite-pwa/assets-generator": "0.2.6",
|
||||
"fake-indexeddb": "6.0.0",
|
||||
"happy-dom": "17.1.1",
|
||||
"react-scan": "0.1.3"
|
||||
"happy-dom": "17.4.4",
|
||||
"react-scan": "0.2.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ import { atom } from "jotai"
|
||||
import { createAtomHooks } from "~/lib/jotai"
|
||||
|
||||
type Readability = {
|
||||
title: string
|
||||
content: string
|
||||
textContent: string
|
||||
length: number
|
||||
excerpt: string
|
||||
byline: string
|
||||
dir: string
|
||||
siteName: string
|
||||
lang: string
|
||||
publishedTime: string
|
||||
title?: string | null
|
||||
content?: string | null
|
||||
textContent?: string | null
|
||||
length?: number | null
|
||||
excerpt?: string | null
|
||||
byline?: string | null
|
||||
dir?: string | null
|
||||
siteName?: string | null
|
||||
lang?: string | null
|
||||
publishedTime?: string | null
|
||||
}
|
||||
|
||||
const mergeObjectSetter =
|
||||
|
||||
@@ -144,7 +144,7 @@ export const useEntryActions = ({ entryId, view }: { entryId: string; view?: Fee
|
||||
id: COMMAND_ID.entry.copyLink,
|
||||
onClick: runCmdFn(COMMAND_ID.entry.copyLink, [{ entryId }]),
|
||||
hide: !entry?.entries.url,
|
||||
shortcut: shortcuts.entry.copyTitle.key,
|
||||
shortcut: shortcuts.entry.copyLink.key,
|
||||
},
|
||||
{
|
||||
id: COMMAND_ID.entry.openInBrowser,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IN_ELECTRON } from "@follow/shared/constants"
|
||||
import { EventBus } from "@follow/utils/event-bus"
|
||||
import { getOS, isEmptyObject } from "@follow/utils/utils"
|
||||
import { isEmptyObject } from "@follow/utils/utils"
|
||||
import dayjs from "dayjs"
|
||||
import i18next from "i18next"
|
||||
import { toast } from "sonner"
|
||||
@@ -76,11 +76,6 @@ export const loadLanguageAndApply = async (lang: string) => {
|
||||
if (IN_ELECTRON) {
|
||||
importFilePath =
|
||||
(await tipcClient?.resolveAppAsarPath(`dist/renderer/locales/${lang}.js`)) || ""
|
||||
|
||||
// FUCK windows
|
||||
if (getOS() === "Windows") {
|
||||
importFilePath = importFilePath.replaceAll("\\", "/")
|
||||
}
|
||||
} else {
|
||||
importFilePath = `/locales/${lang}.js`
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import type { MediaModel } from "@follow/models/types"
|
||||
|
||||
import { getServerConfigs } from "~/atoms/server-configs"
|
||||
import type { RSSHubRoute } from "~/modules/discover/types"
|
||||
@@ -70,12 +69,6 @@ export const getViewFromRoute = (route: RSSHubRoute) => {
|
||||
return null
|
||||
}
|
||||
|
||||
export const filterSmallMedia = (media: MediaModel) => {
|
||||
return media?.filter(
|
||||
(m) => !(m.type === "photo" && m.width && m.width < 65 && m.height && m.height < 65),
|
||||
)
|
||||
}
|
||||
|
||||
export const getLevelMultiplier = (level: number) => {
|
||||
if (level === 0) {
|
||||
return 0.1
|
||||
|
||||
@@ -45,7 +45,9 @@ const useRegisterEagleCommands = () => {
|
||||
enabled: ELECTRON && enableEagle && view !== undefined,
|
||||
queryFn: async () => {
|
||||
try {
|
||||
await ofetch("http://localhost:41595")
|
||||
await ofetch("http://localhost:41595", {
|
||||
mode: "no-cors",
|
||||
})
|
||||
return true
|
||||
} catch (error: unknown) {
|
||||
return (error as FetchError).data?.code === 401
|
||||
|
||||
@@ -13,7 +13,6 @@ import { useTranslation } from "react-i18next"
|
||||
|
||||
import { SwipeMedia } from "~/components/ui/media/SwipeMedia"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { filterSmallMedia } from "~/lib/utils"
|
||||
import { EntryContent } from "~/modules/entry-content"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
import { useImageDimensions } from "~/store/image"
|
||||
@@ -91,7 +90,7 @@ export const PictureWaterFallItem = memo(function PictureWaterFallItem({
|
||||
}
|
||||
}, [ref, intersectionObserver])
|
||||
|
||||
const media = useMemo(() => filterSmallMedia(entry?.entries.media || []), [entry?.entries.media])
|
||||
const media = entry?.entries.media || []
|
||||
|
||||
if (media?.length === 0) return null
|
||||
if (!entry) return null
|
||||
|
||||
@@ -25,7 +25,6 @@ import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
import { useEntry } from "~/store/entry/hooks"
|
||||
import { useFeedById } from "~/store/feed"
|
||||
|
||||
import { filterSmallMedia } from "../../../lib/utils"
|
||||
import { StarIcon } from "../star-icon"
|
||||
import { EntryTranslation } from "../translation"
|
||||
import type { EntryItemStatelessProps, EntryListItemFC } from "../types"
|
||||
@@ -61,7 +60,7 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
|
||||
const content = entry.entries.content || entry.entries.description
|
||||
|
||||
const parsed = parseSocialMedia(entry.entries)
|
||||
const media = filterSmallMedia(entry.entries.media)
|
||||
const { media } = entry.entries
|
||||
const EntryContentWrapper = autoExpandLongSocialMedia
|
||||
? PassviseFragment
|
||||
: CollapsedSocialMediaItem
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createAtomHooks } from "@follow/utils/jotai"
|
||||
import { atom } from "jotai"
|
||||
import { getStorageNS } from "@follow/utils/ns"
|
||||
import { atomWithStorage } from "jotai/utils"
|
||||
|
||||
export const [, , useMasonryColumnValue, , getMasonryColumnValue, setMasonryColumnValue] =
|
||||
createAtomHooks(atom(-1))
|
||||
createAtomHooks(atomWithStorage(getStorageNS("masonry-column"), -1))
|
||||
|
||||
+2
-4
@@ -3,7 +3,6 @@ import type { MediaModel } from "@follow/models"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { filterSmallMedia } from "~/lib/utils"
|
||||
import { useEntry } from "~/store/entry"
|
||||
|
||||
import { ImageGallery } from "./picture-gallery"
|
||||
@@ -12,15 +11,14 @@ export const ImageGalleryAction = ({ id }: { id: string }) => {
|
||||
const { t } = useTranslation()
|
||||
const images = useEntry(id, (entry) => entry.entries.media)
|
||||
const { present } = useModalStack()
|
||||
const filteredImages = filterSmallMedia(images)
|
||||
if (filteredImages?.length && filteredImages.length > 5) {
|
||||
if (images?.length && images.length > 5) {
|
||||
return (
|
||||
<ActionButton
|
||||
onClick={() => {
|
||||
window.analytics?.capture("entry_content_header_image_gallery_click")
|
||||
present({
|
||||
title: t("entry_actions.image_gallery"),
|
||||
content: () => <ImageGallery images={filteredImages as any as MediaModel[]} />,
|
||||
content: () => <ImageGallery images={images as any as MediaModel[]} />,
|
||||
max: true,
|
||||
clickOutsideToDismiss: true,
|
||||
})
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { getViewport } from "@follow/components/hooks/useViewport.js"
|
||||
import {
|
||||
CircleProgress,
|
||||
MaterialSymbolsProgressActivity,
|
||||
} from "@follow/components/icons/Progress.js"
|
||||
import { CircleProgress } from "@follow/components/icons/Progress.js"
|
||||
import { AutoResizeHeight } from "@follow/components/ui/auto-resize-height/index.js"
|
||||
import { Button, MotionButtonBase } from "@follow/components/ui/button/index.js"
|
||||
import { LoadingWithIcon } from "@follow/components/ui/loading/index.jsx"
|
||||
@@ -27,7 +24,6 @@ import {
|
||||
import { enableShowSourceContent } from "~/atoms/source-content"
|
||||
import { CopyButton } from "~/components/ui/button/CopyButton"
|
||||
import { Toc } from "~/components/ui/markdown/components/Toc"
|
||||
import { IconOpacityTransition } from "~/components/ux/transition/icon"
|
||||
import { isWebBuild } from "~/constants"
|
||||
import { useEntryReadabilityToggle } from "~/hooks/biz/useEntryActions"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
@@ -270,7 +266,6 @@ export const ContainerToc: FC = memo(() => {
|
||||
className={cn(
|
||||
"animate-in fade-in-0 slide-in-from-bottom-12 easing-spring spring-soft flex flex-col items-end",
|
||||
"scrollbar-none max-h-[calc(100vh-100px)] overflow-auto",
|
||||
|
||||
"@[700px]:-translate-x-12 @[800px]:-translate-x-16 @[900px]:translate-x-0 @[900px]:items-start",
|
||||
)}
|
||||
/>
|
||||
@@ -289,6 +284,9 @@ export const ContainerToc: FC = memo(() => {
|
||||
const BackTopIndicator: Component = memo(({ className }) => {
|
||||
const [readPercent] = useReadPercent()
|
||||
const scrollElement = useScrollViewElement()
|
||||
|
||||
if (readPercent === 0) return
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
@@ -297,11 +295,7 @@ const BackTopIndicator: Component = memo(({ className }) => {
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-2 tabular-nums">
|
||||
<IconOpacityTransition
|
||||
icon1={<MaterialSymbolsProgressActivity />}
|
||||
icon2={<CircleProgress percent={readPercent!} size={14} strokeWidth={2} />}
|
||||
status={readPercent === 0 ? "init" : "done"}
|
||||
/>
|
||||
<CircleProgress percent={readPercent!} size={14} strokeWidth={2} />
|
||||
<span>{readPercent}%</span>
|
||||
<br />
|
||||
</div>
|
||||
|
||||
@@ -15,7 +15,9 @@ function AuthProviderButton({ provider }: { provider: string }) {
|
||||
const { data: accounts } = useSocialAccounts()
|
||||
const unlinkAccountMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
const res = await unlinkAccount({ providerId: provider })
|
||||
const account = accounts?.find((account) => account.provider === provider)
|
||||
if (!account) throw new Error("Account not found")
|
||||
const res = await unlinkAccount({ providerId: provider, accountId: account.id })
|
||||
if (res.error) throw new Error(res.error.message)
|
||||
},
|
||||
onSuccess: () => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { User } from "@auth/core/types"
|
||||
import { isMobile, useMobile } from "@follow/components/hooks/useMobile.js"
|
||||
import { PhUsersBold } from "@follow/components/icons/users.jsx"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@follow/components/ui/avatar/index.jsx"
|
||||
@@ -6,7 +5,7 @@ import { ActionButton, Button } from "@follow/components/ui/button/index.js"
|
||||
import { LoadingWithIcon } from "@follow/components/ui/loading/index.jsx"
|
||||
import { ScrollArea } from "@follow/components/ui/scroll-area/index.js"
|
||||
import { EllipsisHorizontalTextWithTooltip } from "@follow/components/ui/typography/index.js"
|
||||
import type { FeedModel, Models } from "@follow/models"
|
||||
import type { FeedModel, Models, UserModel } from "@follow/models"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
@@ -150,7 +149,7 @@ const UserCount: Component<{ count: number }> = ({ count, className }) => {
|
||||
}
|
||||
|
||||
interface TopUserAvatarProps {
|
||||
user: User
|
||||
user: UserModel
|
||||
position: string
|
||||
}
|
||||
|
||||
@@ -170,7 +169,7 @@ const TopUserAvatar: React.FC<TopUserAvatarProps> = ({ user, position }) => (
|
||||
</div>
|
||||
)
|
||||
|
||||
const TrendingUsers: FC<{ data: User[] }> = ({ data }) => {
|
||||
const TrendingUsers: FC<{ data: UserModel[] }> = ({ data }) => {
|
||||
const profile = usePresentUserProfileModal("dialog")
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
|
||||
@@ -18,22 +18,15 @@ if (window.SENTRY_RELEASE) {
|
||||
routerCreator = wrapCreateBrowserRouterV7(routerCreator)
|
||||
}
|
||||
|
||||
export const router = routerCreator(
|
||||
[
|
||||
{
|
||||
path: "/",
|
||||
Component: App,
|
||||
children: tree,
|
||||
errorElement: <ErrorElement />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: <NotFound />,
|
||||
},
|
||||
],
|
||||
export const router = routerCreator([
|
||||
{
|
||||
future: {
|
||||
v7_startTransition: true,
|
||||
},
|
||||
path: "/",
|
||||
Component: App,
|
||||
children: tree,
|
||||
errorElement: <ErrorElement />,
|
||||
},
|
||||
)
|
||||
{
|
||||
path: "*",
|
||||
element: <NotFound />,
|
||||
},
|
||||
])
|
||||
|
||||
@@ -15,22 +15,15 @@ if (window.SENTRY_RELEASE) {
|
||||
routerCreator = wrapCreateBrowserRouterV7(routerCreator)
|
||||
}
|
||||
|
||||
export const router = routerCreator(
|
||||
[
|
||||
{
|
||||
path: "/",
|
||||
lazy: () => import("./App"),
|
||||
children: tree,
|
||||
errorElement: <ErrorElement />,
|
||||
},
|
||||
{
|
||||
path: "*",
|
||||
element: <NotFound />,
|
||||
},
|
||||
],
|
||||
export const router = routerCreator([
|
||||
{
|
||||
future: {
|
||||
v7_startTransition: true,
|
||||
},
|
||||
path: "/",
|
||||
lazy: () => import("./App"),
|
||||
children: tree,
|
||||
errorElement: <ErrorElement />,
|
||||
},
|
||||
)
|
||||
{
|
||||
path: "*",
|
||||
element: <NotFound />,
|
||||
},
|
||||
])
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../.env
|
||||
@@ -0,0 +1 @@
|
||||
EXPO_PUBLIC_APP_CHECK_DEBUG_TOKEN=
|
||||
@@ -41,6 +41,7 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
|
||||
LSApplicationCategoryType: "public.app-category.news",
|
||||
ITSAppUsesNonExemptEncryption: false,
|
||||
UIBackgroundModes: ["audio"],
|
||||
LSApplicationQueriesSchemes: ["bilibili", "youtube"],
|
||||
},
|
||||
googleServicesFile: "./build/GoogleService-Info.plist",
|
||||
},
|
||||
@@ -110,12 +111,14 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
|
||||
"expo-secure-store",
|
||||
"@react-native-firebase/app",
|
||||
"@react-native-firebase/crashlytics",
|
||||
"@react-native-firebase/app-check",
|
||||
[
|
||||
"expo-image-picker",
|
||||
{
|
||||
photosPermission: "Allow $(PRODUCT_NAME) to access your photos.",
|
||||
},
|
||||
],
|
||||
"react-native-video",
|
||||
],
|
||||
experiments: {
|
||||
typedRoutes: true,
|
||||
|
||||
@@ -11,9 +11,10 @@ module.exports = function (api) {
|
||||
alias: {
|
||||
"es-toolkit/compat": "../../node_modules/es-toolkit/dist/compat/index.js",
|
||||
"es-toolkit": "../../node_modules/es-toolkit/dist/index.js",
|
||||
"better-auth/react": "../../node_modules/better-auth/dist/react.js",
|
||||
"better-auth/client/plugins": "../../node_modules/better-auth/dist/client/plugins.js",
|
||||
"@better-auth/expo/client": "../../node_modules/@better-auth/expo/dist/client.js",
|
||||
"better-auth/react": "../../node_modules/better-auth/dist/client/react/index.cjs",
|
||||
"better-auth/client/plugins":
|
||||
"../../node_modules/better-auth/dist/client/plugins/index.cjs",
|
||||
"@better-auth/expo/client": "../../node_modules/@better-auth/expo/dist/client.cjs",
|
||||
},
|
||||
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
||||
},
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `entries` ADD `settings` text;
|
||||
@@ -0,0 +1,13 @@
|
||||
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
||||
CREATE TABLE `__new_summaries` (
|
||||
`entry_id` text PRIMARY KEY NOT NULL,
|
||||
`summary` text NOT NULL,
|
||||
`created_at` text,
|
||||
`language` text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
INSERT INTO `__new_summaries`("entry_id", "summary", "created_at", "language") SELECT "entry_id", "summary", "created_at", "language" FROM `summaries`;--> statement-breakpoint
|
||||
DROP TABLE `summaries`;--> statement-breakpoint
|
||||
ALTER TABLE `__new_summaries` RENAME TO `summaries`;--> statement-breakpoint
|
||||
PRAGMA foreign_keys=ON;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `unq` ON `summaries` (`entry_id`,`language`);
|
||||
@@ -0,0 +1,629 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "44da86ee-5ce1-49e9-8f77-992f3fc23a16",
|
||||
"prevId": "1c7389f2-ca2c-47be-bcd1-7b7dece9f457",
|
||||
"tables": {
|
||||
"collections": {
|
||||
"name": "collections",
|
||||
"columns": {
|
||||
"feed_id": {
|
||||
"name": "feed_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"entry_id": {
|
||||
"name": "entry_id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"view": {
|
||||
"name": "view",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"entries": {
|
||||
"name": "entries",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"content": {
|
||||
"name": "content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"source_content": {
|
||||
"name": "source_content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"guid": {
|
||||
"name": "guid",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author": {
|
||||
"name": "author",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author_url": {
|
||||
"name": "author_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author_avatar": {
|
||||
"name": "author_avatar",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"inserted_at": {
|
||||
"name": "inserted_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"published_at": {
|
||||
"name": "published_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"media": {
|
||||
"name": "media",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"categories": {
|
||||
"name": "categories",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"attachments": {
|
||||
"name": "attachments",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"extra": {
|
||||
"name": "extra",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"language": {
|
||||
"name": "language",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"feed_id": {
|
||||
"name": "feed_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"inbox_handle": {
|
||||
"name": "inbox_handle",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"read": {
|
||||
"name": "read",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sources": {
|
||||
"name": "sources",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"settings": {
|
||||
"name": "settings",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"feeds": {
|
||||
"name": "feeds",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"error_at": {
|
||||
"name": "error_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"site_url": {
|
||||
"name": "site_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"owner_user_id": {
|
||||
"name": "owner_user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"error_message": {
|
||||
"name": "error_message",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"images": {
|
||||
"name": "images",
|
||||
"columns": {
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"colors": {
|
||||
"name": "colors",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "(CURRENT_TIMESTAMP)"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"inboxes": {
|
||||
"name": "inboxes",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"lists": {
|
||||
"name": "lists",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"feed_ids": {
|
||||
"name": "feed_ids",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"view": {
|
||||
"name": "view",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"fee": {
|
||||
"name": "fee",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"owner_user_id": {
|
||||
"name": "owner_user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"subscriptions": {
|
||||
"name": "subscriptions",
|
||||
"columns": {
|
||||
"feed_id": {
|
||||
"name": "feed_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"list_id": {
|
||||
"name": "list_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"inbox_id": {
|
||||
"name": "inbox_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"view": {
|
||||
"name": "view",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"is_private": {
|
||||
"name": "is_private",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"category": {
|
||||
"name": "category",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"summaries": {
|
||||
"name": "summaries",
|
||||
"columns": {
|
||||
"entry_id": {
|
||||
"name": "entry_id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"summary": {
|
||||
"name": "summary",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"language": {
|
||||
"name": "language",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"unq": {
|
||||
"name": "unq",
|
||||
"columns": ["entry_id", "language"],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"unread": {
|
||||
"name": "unread",
|
||||
"columns": {
|
||||
"subscription_id": {
|
||||
"name": "subscription_id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"count": {
|
||||
"name": "count",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"users": {
|
||||
"name": "users",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"handle": {
|
||||
"name": "handle",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"is_me": {
|
||||
"name": "is_me",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,629 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "bfd1be54-8339-4937-8c75-52fe36a25d84",
|
||||
"prevId": "44da86ee-5ce1-49e9-8f77-992f3fc23a16",
|
||||
"tables": {
|
||||
"collections": {
|
||||
"name": "collections",
|
||||
"columns": {
|
||||
"feed_id": {
|
||||
"name": "feed_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"entry_id": {
|
||||
"name": "entry_id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"view": {
|
||||
"name": "view",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"entries": {
|
||||
"name": "entries",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"content": {
|
||||
"name": "content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"source_content": {
|
||||
"name": "source_content",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"guid": {
|
||||
"name": "guid",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author": {
|
||||
"name": "author",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author_url": {
|
||||
"name": "author_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author_avatar": {
|
||||
"name": "author_avatar",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"inserted_at": {
|
||||
"name": "inserted_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"published_at": {
|
||||
"name": "published_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"media": {
|
||||
"name": "media",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"categories": {
|
||||
"name": "categories",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"attachments": {
|
||||
"name": "attachments",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"extra": {
|
||||
"name": "extra",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"language": {
|
||||
"name": "language",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"feed_id": {
|
||||
"name": "feed_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"inbox_handle": {
|
||||
"name": "inbox_handle",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"read": {
|
||||
"name": "read",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sources": {
|
||||
"name": "sources",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"settings": {
|
||||
"name": "settings",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"feeds": {
|
||||
"name": "feeds",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"error_at": {
|
||||
"name": "error_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"site_url": {
|
||||
"name": "site_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"owner_user_id": {
|
||||
"name": "owner_user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"error_message": {
|
||||
"name": "error_message",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"images": {
|
||||
"name": "images",
|
||||
"columns": {
|
||||
"url": {
|
||||
"name": "url",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"colors": {
|
||||
"name": "colors",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false,
|
||||
"default": "(CURRENT_TIMESTAMP)"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"inboxes": {
|
||||
"name": "inboxes",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"lists": {
|
||||
"name": "lists",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"feed_ids": {
|
||||
"name": "feed_ids",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"description": {
|
||||
"name": "description",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"view": {
|
||||
"name": "view",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"fee": {
|
||||
"name": "fee",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"owner_user_id": {
|
||||
"name": "owner_user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"subscriptions": {
|
||||
"name": "subscriptions",
|
||||
"columns": {
|
||||
"feed_id": {
|
||||
"name": "feed_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"list_id": {
|
||||
"name": "list_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"inbox_id": {
|
||||
"name": "inbox_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"view": {
|
||||
"name": "view",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"is_private": {
|
||||
"name": "is_private",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"category": {
|
||||
"name": "category",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"summaries": {
|
||||
"name": "summaries",
|
||||
"columns": {
|
||||
"entry_id": {
|
||||
"name": "entry_id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"summary": {
|
||||
"name": "summary",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"language": {
|
||||
"name": "language",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"unq": {
|
||||
"name": "unq",
|
||||
"columns": ["entry_id", "language"],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"unread": {
|
||||
"name": "unread",
|
||||
"columns": {
|
||||
"subscription_id": {
|
||||
"name": "subscription_id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"count": {
|
||||
"name": "count",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"users": {
|
||||
"name": "users",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"handle": {
|
||||
"name": "handle",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"image": {
|
||||
"name": "image",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"is_me": {
|
||||
"name": "is_me",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,20 @@
|
||||
"when": 1741226954359,
|
||||
"tag": "0015_colorful_warbird",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 16,
|
||||
"version": "6",
|
||||
"when": 1741572308405,
|
||||
"tag": "0016_curious_carnage",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 17,
|
||||
"version": "6",
|
||||
"when": 1741700557982,
|
||||
"tag": "0017_talented_captain_cross",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import m0012 from "./0012_magenta_thing.sql"
|
||||
import m0013 from "./0013_chunky_stephen_strange.sql"
|
||||
import m0014 from "./0014_chemical_shocker.sql"
|
||||
import m0015 from "./0015_colorful_warbird.sql"
|
||||
import m0016 from "./0016_curious_carnage.sql"
|
||||
import m0017 from "./0017_talented_captain_cross.sql"
|
||||
import journal from "./meta/_journal.json"
|
||||
|
||||
export default {
|
||||
@@ -37,5 +39,7 @@ export default {
|
||||
m0013,
|
||||
m0014,
|
||||
m0015,
|
||||
m0016,
|
||||
m0017,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"peerDependencies": {
|
||||
"expo": "52.0.35",
|
||||
"react": "18.3.1",
|
||||
"react-native": "0.77.0"
|
||||
"react-native": "0.77.1"
|
||||
},
|
||||
"expo": {
|
||||
"autolinking": {
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"SharedWebViewModule",
|
||||
"HelperModule",
|
||||
"ToasterModule",
|
||||
"AppleIntelligenceGlowEffectModule"
|
||||
"AppleIntelligenceGlowEffectModule",
|
||||
"FollowNative.GaleriaModule",
|
||||
"GaleriaAccessoryModule"
|
||||
]
|
||||
},
|
||||
"android": {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// UIImage.swift
|
||||
// FollowNative
|
||||
//
|
||||
// Created by Innei on 2025/3/12.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIImage {
|
||||
|
||||
func withAlpha(_ alpha: CGFloat) -> UIImage {
|
||||
return UIGraphicsImageRenderer(size: size).image { _ in
|
||||
draw(at: .zero, blendMode: .normal, alpha: alpha)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,11 +9,62 @@ import UIKit
|
||||
|
||||
extension UIWindow {
|
||||
|
||||
public static func findRNSNavigationController() -> UINavigationController? {
|
||||
|
||||
guard let window = UIApplication.shared.windows.first else {
|
||||
|
||||
static func findViewController<T: UIViewController>(ofType type: T.Type) -> T? {
|
||||
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||
let window = windowScene.windows.first else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
if let rootVC = window.rootViewController {
|
||||
return findViewControllerInHierarchy(rootVC, ofType: type)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
static private func findViewControllerInHierarchy<T: UIViewController>(_ viewController: UIViewController, ofType type: T.Type) -> T? {
|
||||
|
||||
if let targetVC = viewController as? T {
|
||||
return targetVC
|
||||
}
|
||||
|
||||
|
||||
if let navController = viewController as? UINavigationController {
|
||||
if let visibleVC = navController.visibleViewController {
|
||||
return findViewControllerInHierarchy(visibleVC, ofType: type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let tabController = viewController as? UITabBarController {
|
||||
if let selectedVC = tabController.selectedViewController {
|
||||
return findViewControllerInHierarchy(selectedVC, ofType: type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for childVC in viewController.children {
|
||||
if let foundVC = findViewControllerInHierarchy(childVC, ofType: type) {
|
||||
return foundVC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if let presentedVC = viewController.presentedViewController {
|
||||
return findViewControllerInHierarchy(presentedVC, ofType: type)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
public static func findRNSNavigationController() -> UINavigationController? {
|
||||
|
||||
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||
let window = windowScene.windows.first else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let rootViewController = window.rootViewController
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
|
||||
s.dependency 'ExpoModulesCore'
|
||||
s.dependency 'SnapKit', '~> 5.7.0'
|
||||
s.dependency 'SDWebImage', '~> 5.0'
|
||||
s.dependency 'SPIndicator', '~> 1.6.4'
|
||||
|
||||
# Swift/Objective-C compatibility
|
||||
s.pod_target_xcconfig = {
|
||||
'DEFINES_MODULE' => 'YES',
|
||||
@@ -30,7 +30,7 @@ Pod::Spec.new do |s|
|
||||
s.source_files = "**/*.{h,m,mm,swift,hpp,cpp,js}"
|
||||
|
||||
s.resource_bundles = {
|
||||
'js' => ['SharedWebView/injected/**/*'],
|
||||
'js' => ['Modules/SharedWebView/injected/**/*'],
|
||||
'FollowNative' => ['Media.xcassets'],
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// EntryGaleriaAccessoryView.swift
|
||||
// FollowNative
|
||||
//
|
||||
// Created by Innei on 2025/3/10.
|
||||
//
|
||||
|
||||
import ExpoModulesCore
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
class ExpoEntryGaleriaAccessoryViewProps: ExpoSwiftUI.ViewProps {
|
||||
@Field var author: String = ""
|
||||
@Field var avatarUrl: URL?
|
||||
@Field var publishedAt: Date = .now
|
||||
|
||||
}
|
||||
|
||||
struct ExpoEntryGaleriaAccessoryView: ExpoSwiftUI.View {
|
||||
|
||||
@EnvironmentObject var props: ExpoEntryGaleriaAccessoryViewProps
|
||||
|
||||
var body: some View {
|
||||
let author = props.author
|
||||
let avatarUrl = props.avatarUrl
|
||||
let publishedAt = props.publishedAt
|
||||
|
||||
EntryGaleriaAccessoryView(
|
||||
author: author, avatarUrl: avatarUrl, publishedAt: publishedAt
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct EntryGaleriaAccessoryView: View {
|
||||
var author: String
|
||||
var avatarUrl: URL? = nil
|
||||
var publishedAt: Date
|
||||
var content: String? = nil
|
||||
|
||||
@State private var opacity: Double = 0
|
||||
|
||||
var body: some View {
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
|
||||
HStack(spacing: 8) {
|
||||
|
||||
if let avatarUrl = avatarUrl {
|
||||
AsyncImage(url: avatarUrl) { image in
|
||||
image.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.background(.gray)
|
||||
} placeholder: {
|
||||
Ellipse().background(.gray)
|
||||
}
|
||||
.frame(width: 40, height: 40)
|
||||
.clipShape(Circle())
|
||||
.overlay(
|
||||
Circle()
|
||||
.stroke(Color.gray.opacity(0.3), lineWidth: 1)
|
||||
)
|
||||
} else {
|
||||
Image(systemName: "person.circle.fill")
|
||||
.resizable()
|
||||
.frame(width: 40, height: 40)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
|
||||
// date and author
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(author)
|
||||
.font(.headline)
|
||||
.foregroundColor(.white)
|
||||
|
||||
Text(publishedAt, style: .relative)
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 16)
|
||||
// Spacer()
|
||||
|
||||
ScrollView {
|
||||
WebViewManager.swiftUIView.frame(height: WebViewManager.state.contentHeight)
|
||||
}
|
||||
.frame(
|
||||
height: WebViewManager.state.contentHeight > 0
|
||||
? min(WebViewManager.state.contentHeight, 100) : nil
|
||||
)
|
||||
.padding(.horizontal, 16)
|
||||
|
||||
.background(
|
||||
LinearGradient(
|
||||
gradient: Gradient(colors: [Color.clear, Color.black]),
|
||||
startPoint: .top,
|
||||
endPoint: .bottom
|
||||
)
|
||||
)
|
||||
|
||||
.ignoresSafeArea(.all)
|
||||
.opacity(opacity)
|
||||
.onAppear {
|
||||
WebViewManager.shared.evaluateJavaScript("setNoMedia(true)")
|
||||
withAnimation(.smooth) {
|
||||
opacity = 1.0
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
WebViewManager.shared.evaluateJavaScript("setNoMedia(false)")
|
||||
}
|
||||
|
||||
}
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// GaleriaAccessoryModule.swift
|
||||
// FollowNative
|
||||
//
|
||||
// Created by Innei on 2025/3/10.
|
||||
//
|
||||
|
||||
import ExpoModulesCore
|
||||
import SwiftUI
|
||||
|
||||
struct EntryGaleriaAccessoryProps: Record {
|
||||
@Field var author: String
|
||||
@Field var avatarUrl: String?
|
||||
@Field var publishedAt: Date = .distantFuture
|
||||
}
|
||||
|
||||
public class GaleriaAccessoryModule: Module {
|
||||
// Use NSMapTable to weakly reference VCs and their accessory views
|
||||
private static var accessoryViews = NSMapTable<ImageCarouselViewController, UIView>
|
||||
.weakToWeakObjects()
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("FollowGaleriaAccessory")
|
||||
|
||||
Function("showEntryGaleriaAccessory") { (props: EntryGaleriaAccessoryProps) in
|
||||
DispatchQueue.main.async {
|
||||
guard let galeriaVC = UIWindow.findViewController(ofType: ImageCarouselViewController.self)
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if this VC has already added an accessory view
|
||||
if GaleriaAccessoryModule.accessoryViews.object(forKey: galeriaVC) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
let avatarURL = URL(string: props.avatarUrl ?? "")
|
||||
|
||||
let hostingVC = UIHostingController(
|
||||
rootView: EntryGaleriaAccessoryView(
|
||||
author: props.author, avatarUrl: avatarURL, publishedAt: props.publishedAt))
|
||||
|
||||
if let galeriaView = galeriaVC.view, let window = galeriaView.window {
|
||||
hostingVC.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
galeriaView.addSubview(hostingVC.view)
|
||||
|
||||
hostingVC.view.backgroundColor = .clear
|
||||
hostingVC.view.sizeToFit()
|
||||
hostingVC.view.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
hostingVC.view.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
hostingVC.view.leadingAnchor.constraint(equalTo: window.leadingAnchor),
|
||||
hostingVC.view.trailingAnchor.constraint(equalTo: window.trailingAnchor),
|
||||
hostingVC.view.bottomAnchor.constraint(equalTo: window.bottomAnchor),
|
||||
])
|
||||
|
||||
|
||||
// Associate the accessory view with the VC
|
||||
GaleriaAccessoryModule.accessoryViews.setObject(hostingVC.view, forKey: galeriaVC)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// GaleriaModule.swift
|
||||
// Pods
|
||||
// Copy from https://github.dev/nandorojo/galeria
|
||||
// Created by Innei on 2025/3/10.
|
||||
//
|
||||
|
||||
import ExpoModulesCore
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
public class GaleriaModule: Module {
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("FollowGaleria")
|
||||
|
||||
View(GaleriaView.self) {
|
||||
Events("onPreview")
|
||||
Events("onClosePreview")
|
||||
Events("onChangeIndex")
|
||||
|
||||
Prop("urls") { (view, urls: [String]?) in
|
||||
view.urls = urls
|
||||
}
|
||||
|
||||
Prop("index") { (view, index: Int?) in
|
||||
view.initialIndex = index
|
||||
}
|
||||
Prop("rightNavItemIconName") { (view, rightNavItemIconName: String) in
|
||||
view.rightNavItemIconName = rightNavItemIconName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// GaleriaView.swift
|
||||
// Copy from https://github.dev/nandorojo/galeria
|
||||
//
|
||||
// Created by Innei on 2025/3/10.
|
||||
//
|
||||
|
||||
import ExpoModulesCore
|
||||
import UIKit
|
||||
|
||||
class GaleriaView: ExpoView {
|
||||
|
||||
override required init(appContext: AppContext? = nil) {
|
||||
super.init(appContext: appContext)
|
||||
}
|
||||
|
||||
|
||||
func getChildImageView() -> UIImageView? {
|
||||
var reactSubviews: [UIView]? = nil
|
||||
if RCTIsNewArchEnabled() {
|
||||
reactSubviews = self.subviews
|
||||
} else {
|
||||
reactSubviews = self.reactSubviews()
|
||||
}
|
||||
|
||||
guard let reactSubviews else { return nil }
|
||||
|
||||
for reactSubview in reactSubviews {
|
||||
for subview in reactSubview.subviews {
|
||||
if let imageView = subview as? UIImageView {
|
||||
return imageView
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
override func insertReactSubview(_ subview: UIView!, at atIndex: Int) {
|
||||
super.insertReactSubview(subview, at: atIndex)
|
||||
if !RCTIsNewArchEnabled() {
|
||||
setupImageView()
|
||||
}
|
||||
}
|
||||
|
||||
override func insertSubview(_ subview: UIView, at atIndex: Int) {
|
||||
super.insertSubview(subview, at: atIndex)
|
||||
if RCTIsNewArchEnabled() {
|
||||
setupImageView()
|
||||
}
|
||||
}
|
||||
|
||||
var urls: [String]? { didSet { setupImageView() } }
|
||||
var initialIndex: Int? { didSet { setupImageView() } }
|
||||
var closeIconName: String?
|
||||
var rightNavItemIconName: String?
|
||||
let onPressRightNavItemIcon = EventDispatcher()
|
||||
let onPreview = EventDispatcher()
|
||||
let onClosePreview = EventDispatcher()
|
||||
let onIndexChange = EventDispatcher()
|
||||
|
||||
func setupImageView() {
|
||||
|
||||
guard let childImage = getChildImageView() else {
|
||||
return
|
||||
}
|
||||
|
||||
if let urls = self.urls, let initialIndex = self.initialIndex {
|
||||
setupImageViewerWithUrls(
|
||||
childImage, urls: urls, initialIndex: initialIndex)
|
||||
} else {
|
||||
setupImageViewerWithSingleImage(childImage)
|
||||
}
|
||||
}
|
||||
|
||||
private func setupImageViewerWithUrls(
|
||||
_ childImage: UIImageView, urls: [String], initialIndex: Int
|
||||
) {
|
||||
let urlObjects = urls.compactMap(URL.init(string:))
|
||||
let options = buildImageViewerOptions()
|
||||
|
||||
childImage.setupImageViewer(urls: urlObjects, initialIndex: initialIndex, options: options)
|
||||
}
|
||||
|
||||
private func setupImageViewerWithSingleImage(
|
||||
_ childImage: UIImageView
|
||||
) {
|
||||
guard let img = childImage.image else {
|
||||
print("Missing image in childImage: \(childImage)")
|
||||
return
|
||||
}
|
||||
let options = buildImageViewerOptions()
|
||||
|
||||
childImage.setupImageViewer(images: [img], options: options)
|
||||
}
|
||||
|
||||
private func buildImageViewerOptions() -> [ImageViewerOption] {
|
||||
|
||||
var options: [ImageViewerOption] = []
|
||||
let iconColor: UIColor = .white
|
||||
|
||||
options.append(
|
||||
ImageViewerOption.onPreview { [weak self] index in
|
||||
self?.onPreview(["index": index])
|
||||
})
|
||||
|
||||
options.append(
|
||||
ImageViewerOption.onClosePreview { [weak self] in
|
||||
self?.onClosePreview()
|
||||
})
|
||||
|
||||
options.append(
|
||||
ImageViewerOption.onIndexChange { [weak self] index in
|
||||
self?.onIndexChange(["index": index])
|
||||
})
|
||||
return options
|
||||
}
|
||||
}
|
||||
+65
@@ -28,6 +28,55 @@ class PreviewControllerController: QLPreviewController, QLPreviewControllerDataS
|
||||
self.initialIndex = initialIndex
|
||||
}
|
||||
|
||||
func prepareImages(imageUrls: [String], initialIndex: Int = 0) {
|
||||
self.initialIndex = initialIndex
|
||||
self.imageDataArray = []
|
||||
|
||||
// Create a dispatch group to wait for all downloads
|
||||
let group = DispatchGroup()
|
||||
|
||||
for url in imageUrls {
|
||||
group.enter()
|
||||
|
||||
// Use the same caching mechanism as FollowImageURLSchemeHandler
|
||||
let originalURLString = url.removingPercentEncoding ?? url
|
||||
let cacheKey = originalURLString
|
||||
let imageCache = SDImageCache.shared
|
||||
|
||||
// Check if image is already cached
|
||||
if let cachedData = imageCache.diskImageData(forKey: cacheKey) {
|
||||
self.imageDataArray.append(cachedData)
|
||||
group.leave()
|
||||
} else {
|
||||
// Download the image if not cached
|
||||
SDWebImageManager.shared.loadImage(
|
||||
with: URL(string: url),
|
||||
options: [],
|
||||
progress: nil
|
||||
) { (image, data, error, _, _, _) in
|
||||
if let imageData = data {
|
||||
// Store in cache using the same key as FollowImageURLSchemeHandler
|
||||
imageCache.storeImageData(toDisk: imageData, forKey: cacheKey)
|
||||
self.imageDataArray.append(imageData)
|
||||
} else if let image = image, let data = image.sd_imageData() {
|
||||
// Store in cache using the same key as FollowImageURLSchemeHandler
|
||||
imageCache.storeImageData(toDisk: data, forKey: cacheKey)
|
||||
self.imageDataArray.append(data)
|
||||
}
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for all downloads to complete
|
||||
group.notify(queue: .main) {
|
||||
// Refresh the view if it's already loaded
|
||||
if self.isViewLoaded {
|
||||
self.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func previewController(_ controller: QLPreviewController, previewItemAt index: Int)
|
||||
-> QLPreviewItem
|
||||
{
|
||||
@@ -119,6 +168,22 @@ class ImagePreview: NSObject {
|
||||
|
||||
rootViewController.present(previewController, animated: true)
|
||||
}
|
||||
|
||||
public static func quickLookImageUrls(_ imageUrls: [String], index: Int = 0) {
|
||||
guard let rootViewController = Utils.getRootVC() else {
|
||||
return
|
||||
}
|
||||
|
||||
if imageUrls.count == 0 {
|
||||
print("no preview urls")
|
||||
return
|
||||
}
|
||||
|
||||
let previewController = PreviewControllerController()
|
||||
previewController.prepareImages(imageUrls: imageUrls, initialIndex: index)
|
||||
|
||||
rootViewController.present(previewController, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
extension SDImageFormat {
|
||||
+8
-17
@@ -14,18 +14,22 @@ public class HelperModule: Module {
|
||||
public func definition() -> ExpoModulesCore.ModuleDefinition {
|
||||
Name("Helper")
|
||||
|
||||
Function("openLink") { (urlString: String) in
|
||||
AsyncFunction("openLink") { (urlString: String, promise: Promise) in
|
||||
guard let url = URL(string: urlString) else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
guard let rootVC = UIApplication.shared.windows.first?.rootViewController else { return }
|
||||
WebViewManager.presentModalWebView(url: url, from: rootVC)
|
||||
guard let rootVC = Utils.getRootVC() else { return }
|
||||
|
||||
let onDismiss = {
|
||||
promise.resolve(["type": "dismiss"])
|
||||
}
|
||||
|
||||
WebViewManager.presentModalWebView(url: url, from: rootVC, onDismiss: onDismiss)
|
||||
}
|
||||
}
|
||||
|
||||
Function("scrollToTop") { (reactTag: Int) in
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let bridge = self?.appContext?.reactBridge else {
|
||||
|
||||
@@ -33,7 +37,6 @@ public class HelperModule: Module {
|
||||
}
|
||||
|
||||
if let sourceView = bridge.uiManager.view(forReactTag: NSNumber(value: reactTag)) {
|
||||
// debugPrint(sourceView, "sourceView")
|
||||
|
||||
let scrollView = self?.findUIScrollView(view: sourceView)
|
||||
guard let scrollView = scrollView else {
|
||||
@@ -45,18 +48,6 @@ public class HelperModule: Module {
|
||||
|
||||
}
|
||||
|
||||
Function("previewImage") { (images: [String]) in
|
||||
let imagesData: [Data] =
|
||||
images.compactMap { image in
|
||||
let url = URL(string: image)
|
||||
let data = try? Data(contentsOf: url!)
|
||||
return data
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
ImagePreview.quickLookImage(imagesData)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+13
-8
@@ -29,7 +29,7 @@ class FOWebView: WKWebView {
|
||||
private var state: WebViewState!
|
||||
|
||||
init(frame: CGRect, state: WebViewState) {
|
||||
let configuration = FOWKWebViewConfiguration()
|
||||
let configuration = FOWKWebViewConfiguration.shared
|
||||
|
||||
super.init(frame: frame, configuration: configuration)
|
||||
configuration.userContentController.add(self, name: "message")
|
||||
@@ -46,6 +46,7 @@ class FOWebView: WKWebView {
|
||||
}
|
||||
|
||||
private class FOWKWebViewConfiguration: WKWebViewConfiguration {
|
||||
static public let shared = FOWKWebViewConfiguration()
|
||||
override init() {
|
||||
super.init()
|
||||
let configuration = self
|
||||
@@ -76,6 +77,8 @@ private class FOWKWebViewConfiguration: WKWebViewConfiguration {
|
||||
)
|
||||
|
||||
let atStartScripts = WKWebView.loadInjectedJs(forResource: "at_start")
|
||||
|
||||
|
||||
|
||||
if let jsString = atStartScripts {
|
||||
let script = WKUserScript(
|
||||
@@ -99,29 +102,29 @@ private class FOWKWebViewConfiguration: WKWebViewConfiguration {
|
||||
forMainFrameOnly: true
|
||||
)
|
||||
|
||||
let schemeHandler = CustomURLSchemeHandler()
|
||||
let schemeHandler = FollowImageURLSchemeHandler()
|
||||
configuration.setURLSchemeHandler(
|
||||
schemeHandler, forURLScheme: CustomURLSchemeHandler.rewriteScheme)
|
||||
schemeHandler, forURLScheme: FollowImageURLSchemeHandler.rewriteScheme)
|
||||
|
||||
let customSchemeScript = WKUserScript(
|
||||
source: """
|
||||
(function() {
|
||||
const originalXHROpen = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function(method, url, ...args) {
|
||||
const modifiedUrl = url.replace(/^https?:/, '\(CustomURLSchemeHandler.rewriteScheme):');
|
||||
const modifiedUrl = url.replace(/^https?:/, '\(FollowImageURLSchemeHandler.rewriteScheme):');
|
||||
originalXHROpen.call(this, method, modifiedUrl, ...args);
|
||||
};
|
||||
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = function(url, options) {
|
||||
const modifiedUrl = url.replace(/^https?:/, '\(CustomURLSchemeHandler.rewriteScheme):');
|
||||
const modifiedUrl = url.replace(/^https?:/, '\(FollowImageURLSchemeHandler.rewriteScheme):');
|
||||
return originalFetch(modifiedUrl, options);
|
||||
};
|
||||
|
||||
const originalImageSrc = Object.getOwnPropertyDescriptor(Image.prototype, 'src');
|
||||
Object.defineProperty(Image.prototype, 'src', {
|
||||
set: function(url) {
|
||||
const modifiedUrl = url.replace(/^https?:/, '\(CustomURLSchemeHandler.rewriteScheme):');
|
||||
const modifiedUrl = url.replace(/^https?:/, '\(FollowImageURLSchemeHandler.rewriteScheme):');
|
||||
originalImageSrc.set.call(this, modifiedUrl);
|
||||
}
|
||||
});
|
||||
@@ -197,8 +200,10 @@ extension FOWebView: WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate
|
||||
|
||||
guard let data = data else { return }
|
||||
DispatchQueue.main.async {
|
||||
ImagePreview.quickLookImage(
|
||||
data.payload.images.compactMap { Data($0) })
|
||||
let urls = data.payload.imageUrls
|
||||
if !urls.isEmpty {
|
||||
ImagePreview.quickLookImageUrls(urls)
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
+55
-6
@@ -6,17 +6,45 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SDWebImage
|
||||
import WebKit
|
||||
|
||||
class CustomURLSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
static let rewriteScheme = "follow-xhr"
|
||||
class FollowImageURLSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
static let rewriteScheme = "follow-image"
|
||||
private var activeTasks: [String: URLSessionDataTask] = [:]
|
||||
private var stoppedTasks: Set<String> = []
|
||||
|
||||
private let imageCache = SDImageCache.shared
|
||||
|
||||
private func getCommonHeaders(forImageData data: Data? = nil) -> [String: String] {
|
||||
var headers = [
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "*",
|
||||
|
||||
]
|
||||
|
||||
if let imageData = data {
|
||||
if imageData.starts(with: [0xFF, 0xD8, 0xFF]) {
|
||||
headers["Content-Type"] = "image/jpeg"
|
||||
} else if imageData.starts(with: [0x89, 0x50, 0x4E, 0x47]) {
|
||||
headers["Content-Type"] = "image/png"
|
||||
} else if imageData.starts(with: [0x47, 0x49, 0x46]) {
|
||||
headers["Content-Type"] = "image/gif"
|
||||
} else if imageData.starts(with: [0x52, 0x49, 0x46, 0x46]) {
|
||||
headers["Content-Type"] = "image/webp"
|
||||
} else {
|
||||
headers["Content-Type"] = "application/octet-stream"
|
||||
}
|
||||
}
|
||||
|
||||
return headers
|
||||
}
|
||||
|
||||
func webView(_ webView: WKWebView, start urlSchemeTask: WKURLSchemeTask) {
|
||||
guard let url = urlSchemeTask.request.url,
|
||||
let originalURLString = url.absoluteString.replacingOccurrences(
|
||||
of: CustomURLSchemeHandler.rewriteScheme, with: "https"
|
||||
of: FollowImageURLSchemeHandler.rewriteScheme, with: "https"
|
||||
).removingPercentEncoding,
|
||||
let originalURL = URL(string: originalURLString)
|
||||
else {
|
||||
@@ -24,6 +52,21 @@ class CustomURLSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
return
|
||||
}
|
||||
|
||||
let cacheKey = originalURL.absoluteString
|
||||
if let cachedData = imageCache.diskImageData(forKey: cacheKey) {
|
||||
let response = HTTPURLResponse(
|
||||
url: originalURL,
|
||||
statusCode: 200,
|
||||
httpVersion: "HTTP/1.1",
|
||||
headerFields: getCommonHeaders(forImageData: cachedData)
|
||||
)!
|
||||
|
||||
urlSchemeTask.didReceive(response)
|
||||
urlSchemeTask.didReceive(cachedData)
|
||||
urlSchemeTask.didFinish()
|
||||
return
|
||||
}
|
||||
|
||||
var request = URLRequest(url: originalURL)
|
||||
|
||||
request.httpMethod = urlSchemeTask.request.httpMethod
|
||||
@@ -38,6 +81,8 @@ class CustomURLSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
let origin = "\(scheme)://\(host)\(urlComponents.port.map { ":\($0)" } ?? "")"
|
||||
headers["Referer"] = origin
|
||||
headers["Origin"] = origin
|
||||
headers["User-Agent"] =
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
|
||||
}
|
||||
request.allHTTPHeaderFields = headers
|
||||
@@ -60,10 +105,14 @@ class CustomURLSchemeHandler: NSObject, WKURLSchemeHandler {
|
||||
if let response = response as? HTTPURLResponse, let data = data {
|
||||
guard !self.stoppedTasks.contains(taskID) else { return }
|
||||
|
||||
// Cache the image data
|
||||
self.imageCache.storeImageData(toDisk: data, forKey: cacheKey)
|
||||
|
||||
var newHeaders = response.allHeaderFields as? [String: String] ?? [:]
|
||||
newHeaders["Access-Control-Allow-Origin"] = "*"
|
||||
newHeaders["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
|
||||
newHeaders["Access-Control-Allow-Headers"] = "*"
|
||||
|
||||
for (key, value) in self.getCommonHeaders(forImageData: data) {
|
||||
newHeaders[key] = value
|
||||
}
|
||||
|
||||
let modifiedResponse = HTTPURLResponse(
|
||||
url: response.url!,
|
||||
+2
-4
@@ -27,10 +27,8 @@
|
||||
send({
|
||||
type: "previewImage",
|
||||
payload: {
|
||||
images: data.images.map((image) => Array.from(image)),
|
||||
index: data.index,
|
||||
ext: data.ext,
|
||||
filename: data.filename,
|
||||
imageUrls: data.imageUrls,
|
||||
index: data.index || 0,
|
||||
},
|
||||
})
|
||||
},
|
||||
+1
-1
@@ -20,7 +20,7 @@ struct BridgeDataBasePayload: Codable {
|
||||
}
|
||||
|
||||
struct PreviewImagePayloadProps: Codable {
|
||||
var images: [[UInt8]]
|
||||
var imageUrls: [String]
|
||||
var index: Int = 0
|
||||
}
|
||||
|
||||
+38
-32
@@ -7,6 +7,7 @@
|
||||
import Combine
|
||||
import ExpoModulesCore
|
||||
import SafariServices
|
||||
import SwiftUI
|
||||
@preconcurrency import WebKit
|
||||
|
||||
private var pendingJavaScripts: [String] = []
|
||||
@@ -35,14 +36,11 @@ enum WebViewManager {
|
||||
} else {
|
||||
webView.evaluateJavaScript(js)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static private(set) var shared: WKWebView = {
|
||||
FOWebView(frame: .zero, state: state)
|
||||
|
||||
}()
|
||||
|
||||
static func resetWebView() {
|
||||
@@ -50,36 +48,44 @@ enum WebViewManager {
|
||||
self.shared = FOWebView(frame: .zero, state: state)
|
||||
}
|
||||
|
||||
static func presentModalWebView(url: URL, from viewController: UIViewController) {
|
||||
static func presentModalWebView(url: URL, from viewController: UIViewController, onDismiss: (() -> Void)? = nil) {
|
||||
let safariVC = SafariViewController(url: url)
|
||||
safariVC.view.tintColor = Utils.accentColor
|
||||
safariVC.preferredControlTintColor = Utils.accentColor
|
||||
|
||||
if let onDismiss = onDismiss { safariVC.setOnDismiss(onDismiss) }
|
||||
viewController.present(safariVC, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
let safariVC = SFSafariViewController(url: url)
|
||||
safariVC.view.tintColor = Utils.accentColor
|
||||
safariVC.preferredControlTintColor = Utils.accentColor
|
||||
viewController.present(safariVC, animated: true)
|
||||
// SwiftUI wrapper for the shared WKWebView
|
||||
struct SharedWebViewUI: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> WKWebView {
|
||||
return WebViewManager.shared
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: WKWebView, context: Context) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extension WebViewManager {
|
||||
static var swiftUIView: some View {
|
||||
SharedWebViewUI()
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate class SafariViewController: SFSafariViewController {
|
||||
|
||||
private var onDismiss: (() -> Void)?
|
||||
|
||||
public func setOnDismiss(_ onDismiss: @escaping () -> Void) {
|
||||
self.onDismiss = onDismiss
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
onDismiss?()
|
||||
}
|
||||
}
|
||||
//
|
||||
//extension WebViewManager {
|
||||
// private static var contentHeightChangeListeners: [Int: (Float) -> Void] = [:]
|
||||
// private static var contentHeightChangeListenerId = 0
|
||||
//
|
||||
// static func addContentHeightChangeListener(_ listener: @escaping (Float) -> Void) -> Int {
|
||||
// let listenerId = contentHeightChangeListenerId
|
||||
// contentHeightChangeListenerId += 1
|
||||
// contentHeightChangeListeners[listenerId] = listener
|
||||
// return listenerId
|
||||
// }
|
||||
//
|
||||
// static func removeContentHeightChangeListener(_ listenerId: Int) {
|
||||
// contentHeightChangeListeners.removeValue(forKey: listenerId)
|
||||
// }
|
||||
//
|
||||
//// static func notifyContentHeightChange(_ height: Float) {
|
||||
//// for listener in contentHeightChangeListeners.values {
|
||||
//// DispatchQueue.main.async {
|
||||
//// listener(height)
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//}
|
||||
-1
@@ -5,7 +5,6 @@
|
||||
//
|
||||
|
||||
import ExpoModulesCore
|
||||
import SPIndicator
|
||||
|
||||
enum ToastType: String, Enumerable {
|
||||
case error
|
||||
@@ -0,0 +1,310 @@
|
||||
import UIKit
|
||||
|
||||
public protocol ImageDataSource: AnyObject {
|
||||
func numberOfImages() -> Int
|
||||
func imageItem(at index: Int) -> ImageItem
|
||||
}
|
||||
|
||||
public class ImageCarouselViewController: UIPageViewController,
|
||||
ImageViewerTransitionViewControllerConvertible,
|
||||
UIPageViewControllerDelegate
|
||||
{
|
||||
|
||||
unowned var initialSourceView: UIImageView?
|
||||
var sourceView: UIImageView? {
|
||||
guard let vc = viewControllers?.first as? ImageViewerController else {
|
||||
return nil
|
||||
}
|
||||
return initialIndex == vc.index ? initialSourceView : nil
|
||||
}
|
||||
|
||||
var targetView: UIImageView? {
|
||||
guard let vc = viewControllers?.first as? ImageViewerController else {
|
||||
return nil
|
||||
}
|
||||
return vc.imageView
|
||||
}
|
||||
|
||||
weak var imageDatasource: ImageDataSource?
|
||||
let imageLoader: ImageLoader
|
||||
|
||||
var initialIndex = 0
|
||||
|
||||
var imageContentMode: UIView.ContentMode = .scaleAspectFill
|
||||
var options: [ImageViewerOption] = []
|
||||
|
||||
private var onRightNavBarTapped: ((Int) -> Void)?
|
||||
private var onPreview: ((Int) -> Void)?
|
||||
private var onClosePreview: (() -> Void)?
|
||||
private var onIndexChange: ((Int) -> Void)?
|
||||
|
||||
private(set) lazy var navBar: UINavigationBar = {
|
||||
let navbar = UINavigationBar(frame: .zero)
|
||||
navbar.backgroundColor = .clear
|
||||
navbar.isTranslucent = true
|
||||
navbar.setBackgroundImage(UIImage(), for: .default)
|
||||
navbar.shadowImage = UIImage()
|
||||
return navbar
|
||||
}()
|
||||
|
||||
private(set) lazy var backgroundView: UIView? = {
|
||||
let v = UIView()
|
||||
v.backgroundColor = .black
|
||||
v.alpha = 1.0
|
||||
return v
|
||||
}()
|
||||
|
||||
private(set) lazy var navItem = UINavigationItem()
|
||||
|
||||
private(set) lazy var pageIndicator: UIPageControl = {
|
||||
let pageControl = UIPageControl()
|
||||
pageControl.translatesAutoresizingMaskIntoConstraints = false
|
||||
pageControl.currentPageIndicatorTintColor = .white
|
||||
pageControl.pageIndicatorTintColor = .gray
|
||||
pageControl.isUserInteractionEnabled = false
|
||||
return pageControl
|
||||
}()
|
||||
|
||||
private let imageViewerPresentationDelegate: ImageViewerTransitionPresentationManager
|
||||
|
||||
public init(
|
||||
sourceView: UIImageView,
|
||||
imageDataSource: ImageDataSource?,
|
||||
imageLoader: ImageLoader,
|
||||
options: [ImageViewerOption] = [],
|
||||
initialIndex: Int = 0
|
||||
) {
|
||||
self.initialSourceView = sourceView
|
||||
self.initialIndex = initialIndex
|
||||
self.options = options
|
||||
self.imageDatasource = imageDataSource
|
||||
self.imageLoader = imageLoader
|
||||
let pageOptions = [UIPageViewController.OptionsKey.interPageSpacing: 20]
|
||||
|
||||
var _imageContentMode = imageContentMode
|
||||
options.forEach {
|
||||
switch $0 {
|
||||
case .contentMode(let contentMode):
|
||||
_imageContentMode = contentMode
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
imageContentMode = _imageContentMode
|
||||
|
||||
self.imageViewerPresentationDelegate = ImageViewerTransitionPresentationManager(
|
||||
imageContentMode: imageContentMode)
|
||||
super.init(
|
||||
transitionStyle: .scroll,
|
||||
navigationOrientation: .horizontal,
|
||||
options: pageOptions)
|
||||
self.view.overrideUserInterfaceStyle = .dark
|
||||
transitioningDelegate = imageViewerPresentationDelegate
|
||||
modalPresentationStyle = .custom
|
||||
modalPresentationCapturesStatusBarAppearance = true
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
private func addNavBar() {
|
||||
let closeBarButton = UIBarButtonItem(
|
||||
barButtonSystemItem: .close,
|
||||
target: self,
|
||||
action: #selector(dismiss(_:)))
|
||||
|
||||
let saveAction = UIAction(
|
||||
title: "Save to Photos",
|
||||
image: UIImage(systemName: "square.and.arrow.down")
|
||||
) { [weak self] _ in
|
||||
self?.saveImageToPhotos()
|
||||
}
|
||||
|
||||
let copyAction = UIAction(
|
||||
title: "Copy",
|
||||
image: UIImage(systemName: "doc.on.doc")
|
||||
) { [weak self] _ in
|
||||
self?.copyImageToClipboard()
|
||||
}
|
||||
|
||||
let shareAction = UIAction(
|
||||
title: "Share",
|
||||
image: UIImage(systemName: "square.and.arrow.up")
|
||||
) { [weak self] _ in
|
||||
self?.shareImage()
|
||||
}
|
||||
|
||||
let menu = UIMenu(title: "", children: [saveAction, copyAction, shareAction])
|
||||
|
||||
let optionsButton = UIBarButtonItem(
|
||||
image: UIImage(systemName: "ellipsis.circle")?.withAlpha(0.9).withTintColor(
|
||||
.white, renderingMode: .alwaysOriginal
|
||||
),
|
||||
primaryAction: nil,
|
||||
menu: menu
|
||||
)
|
||||
|
||||
navItem.leftBarButtonItem = closeBarButton
|
||||
navItem.rightBarButtonItem = optionsButton
|
||||
navBar.alpha = 0.0
|
||||
navBar.items = [navItem]
|
||||
|
||||
navBar.insert(to: view)
|
||||
}
|
||||
|
||||
private func saveImageToPhotos() {
|
||||
if let vc = viewControllers?.first as? ImageCarouselViewControllerProtocol {
|
||||
vc.saveImageToPhotos()
|
||||
}
|
||||
|
||||
}
|
||||
private func copyImageToClipboard() {
|
||||
if let vc = viewControllers?.first as? ImageCarouselViewControllerProtocol {
|
||||
vc.copyImageToClipboard()
|
||||
}
|
||||
}
|
||||
private func shareImage() {
|
||||
if let vc = viewControllers?.first as? ImageCarouselViewControllerProtocol {
|
||||
vc.shareImage()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private func addBackgroundView() {
|
||||
guard let backgroundView = backgroundView else { return }
|
||||
view.addSubview(backgroundView)
|
||||
backgroundView.bindFrameToSuperview()
|
||||
view.sendSubviewToBack(backgroundView)
|
||||
}
|
||||
|
||||
private func addPageIndicator() {
|
||||
if imageDatasource?.numberOfImages() == 1 { return }
|
||||
view.addSubview(pageIndicator)
|
||||
NSLayoutConstraint.activate([
|
||||
pageIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
pageIndicator.bottomAnchor.constraint(
|
||||
equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20),
|
||||
])
|
||||
|
||||
if let imageDatasource = imageDatasource {
|
||||
pageIndicator.numberOfPages = imageDatasource.numberOfImages()
|
||||
pageIndicator.currentPage = initialIndex
|
||||
}
|
||||
}
|
||||
|
||||
public func setRightNavItem(item: UIBarButtonItem) {
|
||||
navItem.rightBarButtonItem = item
|
||||
}
|
||||
|
||||
private func applyOptions() {
|
||||
|
||||
options.forEach {
|
||||
switch $0 {
|
||||
|
||||
case .contentMode(let contentMode):
|
||||
self.imageContentMode = contentMode
|
||||
case .onPreview(let callback):
|
||||
self.onPreview = callback
|
||||
case .onClosePreview(let callback):
|
||||
self.onClosePreview = callback
|
||||
case .onIndexChange(let callback):
|
||||
self.onIndexChange = callback
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
addBackgroundView()
|
||||
addNavBar()
|
||||
addPageIndicator()
|
||||
applyOptions()
|
||||
|
||||
dataSource = self
|
||||
delegate = self
|
||||
|
||||
if let imageDatasource = imageDatasource {
|
||||
let initialVC: ImageViewerController = .init(
|
||||
index: initialIndex,
|
||||
imageItem: imageDatasource.imageItem(at: initialIndex),
|
||||
imageLoader: imageLoader,
|
||||
sourceView: initialSourceView
|
||||
)
|
||||
setViewControllers([initialVC], direction: .forward, animated: true)
|
||||
onPreview?(initialIndex)
|
||||
}
|
||||
}
|
||||
|
||||
override public func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
if let vc = viewControllers?.first as? ImageViewerController {
|
||||
onPreview?(vc.index)
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func dismiss(_ sender: UIBarButtonItem) {
|
||||
onClosePreview?()
|
||||
self.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
initialSourceView?.alpha = 1.0
|
||||
onClosePreview?()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - UIPageViewControllerDelegate
|
||||
extension ImageCarouselViewController {
|
||||
public func pageViewController(
|
||||
_ pageViewController: UIPageViewController,
|
||||
didFinishAnimating finished: Bool,
|
||||
previousViewControllers: [UIViewController],
|
||||
transitionCompleted completed: Bool
|
||||
) {
|
||||
if completed,
|
||||
let currentVC = pageViewController.viewControllers?.first as? ImageViewerController
|
||||
{
|
||||
pageIndicator.currentPage = currentVC.index
|
||||
onIndexChange?(currentVC.index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ImageCarouselViewController: UIPageViewControllerDataSource {
|
||||
public func pageViewController(
|
||||
_ pageViewController: UIPageViewController,
|
||||
viewControllerBefore viewController: UIViewController
|
||||
) -> UIViewController? {
|
||||
|
||||
guard let vc = viewController as? ImageViewerController else { return nil }
|
||||
guard let imageDatasource = imageDatasource else { return nil }
|
||||
guard vc.index > 0 else { return nil }
|
||||
|
||||
let newIndex = vc.index - 1
|
||||
return ImageViewerController.init(
|
||||
index: newIndex,
|
||||
imageItem: imageDatasource.imageItem(at: newIndex),
|
||||
imageLoader: vc.imageLoader
|
||||
)
|
||||
}
|
||||
|
||||
public func pageViewController(
|
||||
_ pageViewController: UIPageViewController,
|
||||
viewControllerAfter viewController: UIViewController
|
||||
) -> UIViewController? {
|
||||
|
||||
guard let vc = viewController as? ImageViewerController else { return nil }
|
||||
guard let imageDatasource = imageDatasource else { return nil }
|
||||
guard vc.index <= (imageDatasource.numberOfImages() - 2) else { return nil }
|
||||
|
||||
let newIndex = vc.index + 1
|
||||
return ImageViewerController.init(
|
||||
index: newIndex,
|
||||
imageItem: imageDatasource.imageItem(at: newIndex),
|
||||
imageLoader: vc.imageLoader)
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// ImageCarouselViewControllerProtocol.swift
|
||||
// FollowNative
|
||||
//
|
||||
// Created by Innei on 2025/3/12.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
protocol ImageCarouselViewControllerProtocol {
|
||||
func saveImageToPhotos()
|
||||
func copyImageToClipboard()
|
||||
func shareImage()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import UIKit
|
||||
|
||||
public enum ImageItem {
|
||||
case image(UIImage?)
|
||||
case url(URL, placeholder: UIImage?)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import Foundation
|
||||
import SDWebImage
|
||||
|
||||
public protocol ImageLoader {
|
||||
func loadImage(_ url: URL, placeholder: UIImage?, imageView: UIImageView, completion: @escaping (_ image: UIImage?) -> Void)
|
||||
}
|
||||
|
||||
struct SDWebImageLoader: ImageLoader {
|
||||
func loadImage(_ url: URL, placeholder: UIImage?, imageView: UIImageView, completion: @escaping (UIImage?) -> Void) {
|
||||
guard var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return }
|
||||
urlComponents.scheme = "https"
|
||||
guard let httpsURL = urlComponents.url else { return }
|
||||
|
||||
imageView.sd_setImage(
|
||||
with: httpsURL,
|
||||
placeholderImage: placeholder,
|
||||
options: [],
|
||||
progress: nil) {(img, err, type, url) in
|
||||
DispatchQueue.main.async {
|
||||
completion(img)
|
||||
}
|
||||
|
||||
if let error = err {
|
||||
print("Error: \(error.localizedDescription)")
|
||||
if let nsError = error as NSError? {
|
||||
print("Error Code: \(nsError.code), Domain: \(nsError.domain)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
import UIKit
|
||||
|
||||
class ImageViewerController: UIViewController,
|
||||
UIGestureRecognizerDelegate
|
||||
{
|
||||
|
||||
var imageView: UIImageView = UIImageView(frame: .zero)
|
||||
let imageLoader: ImageLoader
|
||||
private var activityIndicator: UIActivityIndicatorView!
|
||||
|
||||
var backgroundView: UIView? {
|
||||
guard let _parent = parent as? ImageCarouselViewController
|
||||
else { return nil }
|
||||
return _parent.backgroundView
|
||||
}
|
||||
|
||||
var index: Int = 0
|
||||
var imageItem: ImageItem!
|
||||
|
||||
var navBar: UINavigationBar? {
|
||||
guard let _parent = parent as? ImageCarouselViewController
|
||||
else { return nil }
|
||||
return _parent.navBar
|
||||
}
|
||||
|
||||
// MARK: Layout Constraints
|
||||
private var top: NSLayoutConstraint!
|
||||
private var leading: NSLayoutConstraint!
|
||||
private var trailing: NSLayoutConstraint!
|
||||
private var bottom: NSLayoutConstraint!
|
||||
|
||||
private var scrollView: UIScrollView!
|
||||
|
||||
private var lastLocation: CGPoint = .zero
|
||||
private var isAnimating: Bool = false
|
||||
private var maxZoomScale: CGFloat = 1.0
|
||||
|
||||
private var sourceView: UIImageView? = nil
|
||||
|
||||
init(
|
||||
index: Int,
|
||||
imageItem: ImageItem,
|
||||
imageLoader: ImageLoader,
|
||||
sourceView: UIImageView? = nil
|
||||
) {
|
||||
|
||||
self.index = index
|
||||
self.imageItem = imageItem
|
||||
self.imageLoader = imageLoader
|
||||
self.sourceView = sourceView
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func loadView() {
|
||||
let view = UIView()
|
||||
|
||||
view.backgroundColor = .clear
|
||||
self.view = view
|
||||
|
||||
scrollView = UIScrollView()
|
||||
scrollView.delegate = self
|
||||
scrollView.showsVerticalScrollIndicator = false
|
||||
scrollView.showsHorizontalScrollIndicator = false
|
||||
scrollView.contentInsetAdjustmentBehavior = .never
|
||||
|
||||
view.addSubview(scrollView)
|
||||
scrollView.bindFrameToSuperview()
|
||||
scrollView.backgroundColor = .clear
|
||||
scrollView.addSubview(imageView)
|
||||
|
||||
activityIndicator = UIActivityIndicatorView(style: .large)
|
||||
activityIndicator.color = .white
|
||||
activityIndicator.hidesWhenStopped = true
|
||||
scrollView.addSubview(activityIndicator)
|
||||
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
|
||||
NSLayoutConstraint.activate([
|
||||
activityIndicator.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
|
||||
activityIndicator.centerYAnchor.constraint(equalTo: scrollView.centerYAnchor),
|
||||
])
|
||||
|
||||
imageView.translatesAutoresizingMaskIntoConstraints = false
|
||||
top = imageView.topAnchor.constraint(equalTo: scrollView.topAnchor)
|
||||
leading = imageView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor)
|
||||
trailing = scrollView.trailingAnchor.constraint(equalTo: imageView.trailingAnchor)
|
||||
bottom = scrollView.bottomAnchor.constraint(equalTo: imageView.bottomAnchor)
|
||||
|
||||
top.isActive = true
|
||||
leading.isActive = true
|
||||
trailing.isActive = true
|
||||
bottom.isActive = true
|
||||
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
switch imageItem {
|
||||
case .image(let img):
|
||||
imageView.image = img
|
||||
imageView.layoutIfNeeded()
|
||||
case .url(let url, let placeholder):
|
||||
activityIndicator.startAnimating()
|
||||
if let sourceView = self.sourceView {
|
||||
imageView.image = sourceView.image
|
||||
}
|
||||
|
||||
if imageView.image == nil {
|
||||
imageView.image = UIImage(systemName: "photo")?.withTintColor(
|
||||
.gray, renderingMode: .alwaysOriginal)
|
||||
}
|
||||
self.layout()
|
||||
imageLoader.loadImage(url, placeholder: placeholder, imageView: imageView) { (image) in
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.layout()
|
||||
self?.activityIndicator.stopAnimating()
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
addGestureRecognizers()
|
||||
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
self.navBar?.alpha = 1.0
|
||||
}
|
||||
|
||||
override func viewDidDisappear(_ animated: Bool) {
|
||||
super.viewDidDisappear(animated)
|
||||
self.navBar?.alpha = 0.0
|
||||
}
|
||||
|
||||
override func viewWillLayoutSubviews() {
|
||||
super.viewWillLayoutSubviews()
|
||||
layout()
|
||||
}
|
||||
|
||||
private func layout() {
|
||||
updateConstraintsForSize(view.bounds.size)
|
||||
updateMinMaxZoomScaleForSize(view.bounds.size)
|
||||
}
|
||||
|
||||
// MARK: Add Gesture Recognizers
|
||||
func addGestureRecognizers() {
|
||||
|
||||
let panGesture = UIPanGestureRecognizer(
|
||||
target: self, action: #selector(didPan(_:)))
|
||||
panGesture.cancelsTouchesInView = false
|
||||
panGesture.delegate = self
|
||||
scrollView.addGestureRecognizer(panGesture)
|
||||
|
||||
let pinchRecognizer = UITapGestureRecognizer(
|
||||
target: self, action: #selector(didPinch(_:)))
|
||||
pinchRecognizer.numberOfTapsRequired = 1
|
||||
pinchRecognizer.numberOfTouchesRequired = 2
|
||||
scrollView.addGestureRecognizer(pinchRecognizer)
|
||||
|
||||
let singleTapGesture = UITapGestureRecognizer(
|
||||
target: self, action: #selector(didSingleTap(_:)))
|
||||
singleTapGesture.numberOfTapsRequired = 1
|
||||
singleTapGesture.numberOfTouchesRequired = 1
|
||||
scrollView.addGestureRecognizer(singleTapGesture)
|
||||
|
||||
let doubleTapRecognizer = UITapGestureRecognizer(
|
||||
target: self, action: #selector(didDoubleTap(_:)))
|
||||
doubleTapRecognizer.numberOfTapsRequired = 2
|
||||
doubleTapRecognizer.numberOfTouchesRequired = 1
|
||||
scrollView.addGestureRecognizer(doubleTapRecognizer)
|
||||
|
||||
singleTapGesture.require(toFail: doubleTapRecognizer)
|
||||
}
|
||||
|
||||
@objc
|
||||
func didPan(_ gestureRecognizer: UIPanGestureRecognizer) {
|
||||
guard
|
||||
isAnimating == false,
|
||||
scrollView.zoomScale == scrollView.minimumZoomScale
|
||||
else { return }
|
||||
|
||||
let container: UIView! = imageView
|
||||
if gestureRecognizer.state == .began {
|
||||
lastLocation = container.center
|
||||
}
|
||||
|
||||
if gestureRecognizer.state != .cancelled {
|
||||
let translation: CGPoint =
|
||||
gestureRecognizer
|
||||
.translation(in: view)
|
||||
container.center = CGPoint(
|
||||
x: lastLocation.x + translation.x,
|
||||
y: lastLocation.y + translation.y)
|
||||
}
|
||||
|
||||
let diffY = view.center.y - container.center.y
|
||||
backgroundView?.alpha = 1.0 - abs(diffY / view.center.y)
|
||||
if gestureRecognizer.state == .ended {
|
||||
if abs(diffY) > 60 {
|
||||
dismiss(animated: true)
|
||||
} else {
|
||||
executeCancelAnimation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func didPinch(_ recognizer: UITapGestureRecognizer) {
|
||||
var newZoomScale = scrollView.zoomScale / 1.5
|
||||
newZoomScale = max(newZoomScale, scrollView.minimumZoomScale)
|
||||
scrollView.setZoomScale(newZoomScale, animated: true)
|
||||
}
|
||||
|
||||
@objc
|
||||
func didSingleTap(_ recognizer: UITapGestureRecognizer) {
|
||||
|
||||
let currentNavAlpha = self.navBar?.alpha ?? 0.0
|
||||
UIView.animate(withDuration: 0.235) {
|
||||
self.navBar?.alpha = currentNavAlpha > 0.5 ? 0.0 : 1.0
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func didDoubleTap(_ recognizer: UITapGestureRecognizer) {
|
||||
let pointInView = recognizer.location(in: imageView)
|
||||
zoomInOrOut(at: pointInView)
|
||||
}
|
||||
|
||||
@objc func image(
|
||||
_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer
|
||||
) {
|
||||
if let error = error {
|
||||
SPIndicator.present(
|
||||
title: "Save Error", message: error.localizedDescription, preset: .error,
|
||||
haptic: .error)
|
||||
} else {
|
||||
SPIndicator.present(title: "Saved", preset: .done, haptic: .success)
|
||||
}
|
||||
}
|
||||
|
||||
func gestureRecognizerShouldBegin(
|
||||
_ gestureRecognizer: UIGestureRecognizer
|
||||
) -> Bool {
|
||||
guard scrollView.zoomScale == scrollView.minimumZoomScale,
|
||||
let panGesture = gestureRecognizer as? UIPanGestureRecognizer
|
||||
else { return false }
|
||||
|
||||
let velocity = panGesture.velocity(in: scrollView)
|
||||
return abs(velocity.y) > abs(velocity.x)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Adjusting the dimensions
|
||||
extension ImageViewerController {
|
||||
|
||||
func updateMinMaxZoomScaleForSize(_ size: CGSize) {
|
||||
|
||||
let targetSize = imageView.bounds.size
|
||||
if targetSize.width == 0 || targetSize.height == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
let minScale = min(
|
||||
size.width / targetSize.width,
|
||||
size.height / targetSize.height)
|
||||
let maxScale = max(
|
||||
(size.width + 1.0) / targetSize.width,
|
||||
(size.height + 1.0) / targetSize.height)
|
||||
|
||||
scrollView.minimumZoomScale = minScale
|
||||
scrollView.zoomScale = minScale
|
||||
maxZoomScale = maxScale
|
||||
scrollView.maximumZoomScale = maxZoomScale * 1.1
|
||||
}
|
||||
|
||||
func zoomInOrOut(at point: CGPoint) {
|
||||
let newZoomScale =
|
||||
scrollView.zoomScale == scrollView.minimumZoomScale
|
||||
? maxZoomScale : scrollView.minimumZoomScale
|
||||
let size = scrollView.bounds.size
|
||||
let w = size.width / newZoomScale
|
||||
let h = size.height / newZoomScale
|
||||
let x = point.x - (w * 0.5)
|
||||
let y = point.y - (h * 0.5)
|
||||
let rect = CGRect(x: x, y: y, width: w, height: h)
|
||||
scrollView.zoom(to: rect, animated: true)
|
||||
}
|
||||
|
||||
func updateConstraintsForSize(_ size: CGSize) {
|
||||
let yOffset = max(0, (size.height - imageView.frame.height) / 2)
|
||||
top.constant = yOffset
|
||||
bottom.constant = yOffset
|
||||
|
||||
let xOffset = max(0, (size.width - imageView.frame.width) / 2)
|
||||
leading.constant = xOffset
|
||||
trailing.constant = xOffset
|
||||
view.layoutIfNeeded()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Animation Related stuff
|
||||
extension ImageViewerController {
|
||||
|
||||
private func executeCancelAnimation() {
|
||||
self.isAnimating = true
|
||||
UIView.animate(
|
||||
withDuration: 0.237,
|
||||
animations: {
|
||||
self.imageView.center = self.view.center
|
||||
self.backgroundView?.alpha = 1.0
|
||||
}
|
||||
) { [weak self] _ in
|
||||
self?.isAnimating = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ImageViewerController: UIScrollViewDelegate {
|
||||
|
||||
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
|
||||
return imageView
|
||||
}
|
||||
|
||||
func scrollViewDidZoom(_ scrollView: UIScrollView) {
|
||||
updateConstraintsForSize(view.bounds.size)
|
||||
}
|
||||
}
|
||||
|
||||
extension ImageViewerController: ImageCarouselViewControllerProtocol {
|
||||
|
||||
public func saveImageToPhotos() {
|
||||
guard let image = imageView.image else { return }
|
||||
|
||||
UIImageWriteToSavedPhotosAlbum(
|
||||
image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
|
||||
}
|
||||
|
||||
public func copyImageToClipboard() {
|
||||
guard let image = imageView.image else { return }
|
||||
|
||||
UIPasteboard.general.image = image
|
||||
SPIndicator.present(title: "Copied", preset: .done, haptic: .success)
|
||||
}
|
||||
|
||||
public func shareImage() {
|
||||
guard let image = imageView.image else { return }
|
||||
|
||||
let activityViewController = UIActivityViewController(
|
||||
activityItems: [image],
|
||||
applicationActivities: nil)
|
||||
|
||||
// For iPad support
|
||||
if let popoverController = activityViewController.popoverPresentationController {
|
||||
popoverController.sourceView = imageView
|
||||
popoverController.sourceRect = CGRect(
|
||||
x: imageView.bounds.midX, y: imageView.bounds.midY, width: 0, height: 0)
|
||||
popoverController.permittedArrowDirections = []
|
||||
}
|
||||
|
||||
present(activityViewController, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import UIKit
|
||||
|
||||
public enum ImageViewerOption {
|
||||
|
||||
case contentMode(UIView.ContentMode)
|
||||
case onPreview((Int) -> Void)
|
||||
case onClosePreview(() -> Void)
|
||||
case onIndexChange((Int) -> Void)
|
||||
}
|
||||
+243
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// ImageViewerTransitionPresentationManager.swift
|
||||
// ImageViewer.swift
|
||||
//
|
||||
// Created by Michael Henry Pantaleon on 2020/08/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
protocol ImageViewerTransitionViewControllerConvertible {
|
||||
|
||||
// The source view
|
||||
var sourceView: UIImageView? { get }
|
||||
|
||||
// The final view
|
||||
var targetView: UIImageView? { get }
|
||||
}
|
||||
|
||||
final class ImageViewerTransitionPresentationAnimator: NSObject {
|
||||
|
||||
let isPresenting: Bool
|
||||
let imageContentMode: UIView.ContentMode
|
||||
|
||||
var observation: NSKeyValueObservation?
|
||||
|
||||
init(isPresenting: Bool, imageContentMode: UIView.ContentMode) {
|
||||
self.isPresenting = isPresenting
|
||||
self.imageContentMode = imageContentMode
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIViewControllerAnimatedTransitioning
|
||||
extension ImageViewerTransitionPresentationAnimator: UIViewControllerAnimatedTransitioning {
|
||||
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?)
|
||||
-> TimeInterval
|
||||
{
|
||||
return 0.3
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
let key: UITransitionContextViewControllerKey = isPresenting ? .to : .from
|
||||
guard let controller = transitionContext.viewController(forKey: key)
|
||||
else { return }
|
||||
|
||||
let animationDuration = transitionDuration(using: transitionContext)
|
||||
|
||||
if isPresenting {
|
||||
presentAnimation(
|
||||
transitionView: transitionContext.containerView,
|
||||
controller: controller,
|
||||
duration: animationDuration
|
||||
) { finished in
|
||||
transitionContext.completeTransition(finished)
|
||||
}
|
||||
|
||||
} else {
|
||||
dismissAnimation(
|
||||
transitionView: transitionContext.containerView,
|
||||
controller: controller,
|
||||
duration: animationDuration
|
||||
) { finished in
|
||||
transitionContext.completeTransition(finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func createDummyImageView(frame: CGRect, image: UIImage? = nil)
|
||||
-> UIImageView
|
||||
{
|
||||
let dummyImageView: UIImageView = UIImageView(frame: frame)
|
||||
dummyImageView.clipsToBounds = true
|
||||
dummyImageView.contentMode = imageContentMode
|
||||
dummyImageView.alpha = 1.0
|
||||
dummyImageView.image = image
|
||||
return dummyImageView
|
||||
}
|
||||
|
||||
private func presentAnimation(
|
||||
transitionView: UIView,
|
||||
controller: UIViewController,
|
||||
duration: TimeInterval,
|
||||
completed: @escaping ((Bool) -> Void)
|
||||
) {
|
||||
|
||||
guard
|
||||
let transitionVC = controller as? ImageViewerTransitionViewControllerConvertible,
|
||||
let sourceView = transitionVC.sourceView
|
||||
else { return }
|
||||
|
||||
sourceView.alpha = 0.0
|
||||
controller.view.alpha = 0.0
|
||||
|
||||
transitionView.addSubview(controller.view)
|
||||
transitionVC.targetView?.alpha = 0.0
|
||||
transitionVC.targetView?.tintColor = sourceView.tintColor
|
||||
|
||||
var dummyImageView: UIImageView?
|
||||
if let image = sourceView.image {
|
||||
dummyImageView = createDummyImageView(
|
||||
frame: sourceView.frameRelativeToWindow(),
|
||||
image: sourceView.image)
|
||||
dummyImageView!.contentMode = .scaleAspectFit
|
||||
dummyImageView!.tintColor = sourceView.tintColor
|
||||
|
||||
transitionView.addSubview(dummyImageView!)
|
||||
}
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
animations: {
|
||||
dummyImageView?.frame = UIScreen.main.bounds
|
||||
controller.view.alpha = 1.0
|
||||
}
|
||||
) { [weak self] finished in
|
||||
|
||||
self?.observation = transitionVC.targetView?.observe(
|
||||
\.image, options: [.new, .initial]
|
||||
) { img, change in
|
||||
if img.image != nil {
|
||||
transitionVC.targetView?.alpha = 1.0
|
||||
dummyImageView?.removeFromSuperview()
|
||||
completed(finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func dismissAnimation(
|
||||
transitionView: UIView,
|
||||
controller: UIViewController,
|
||||
duration: TimeInterval,
|
||||
completed: @escaping ((Bool) -> Void)
|
||||
) {
|
||||
|
||||
guard
|
||||
let transitionVC = controller as? ImageViewerTransitionViewControllerConvertible
|
||||
else { return }
|
||||
|
||||
let sourceView = transitionVC.sourceView
|
||||
let targetView = transitionVC.targetView
|
||||
|
||||
let dummyImageView = createDummyImageView(
|
||||
frame: targetView?.frameRelativeToWindow() ?? UIScreen.main.bounds,
|
||||
image: targetView?.image)
|
||||
dummyImageView.tintColor = sourceView?.tintColor
|
||||
transitionView.addSubview(dummyImageView)
|
||||
targetView?.isHidden = true
|
||||
|
||||
controller.view.alpha = 1.0
|
||||
UIView.animate(
|
||||
withDuration: duration,
|
||||
animations: {
|
||||
if let sourceView = sourceView {
|
||||
// return to original position
|
||||
dummyImageView.frame = sourceView.frameRelativeToWindow()
|
||||
} else {
|
||||
// just disappear
|
||||
dummyImageView.alpha = 0.0
|
||||
}
|
||||
controller.view.alpha = 0.0
|
||||
}
|
||||
) { finished in
|
||||
sourceView?.alpha = 1.0
|
||||
controller.view.removeFromSuperview()
|
||||
completed(finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class ImageViewerTransitionPresentationController: UIPresentationController {
|
||||
|
||||
override var frameOfPresentedViewInContainerView: CGRect {
|
||||
var frame: CGRect = .zero
|
||||
frame.size = size(
|
||||
forChildContentContainer: presentedViewController,
|
||||
withParentContainerSize: containerView!.bounds.size)
|
||||
return frame
|
||||
}
|
||||
|
||||
override func containerViewWillLayoutSubviews() {
|
||||
presentedView?.frame = frameOfPresentedViewInContainerView
|
||||
}
|
||||
}
|
||||
|
||||
final class ImageViewerTransitionPresentationManager: NSObject {
|
||||
private let imageContentMode: UIView.ContentMode
|
||||
|
||||
public init(imageContentMode: UIView.ContentMode) {
|
||||
self.imageContentMode = imageContentMode
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - UIViewControllerTransitioningDelegate
|
||||
extension ImageViewerTransitionPresentationManager: UIViewControllerTransitioningDelegate {
|
||||
func presentationController(
|
||||
forPresented presented: UIViewController,
|
||||
presenting: UIViewController?,
|
||||
source: UIViewController
|
||||
) -> UIPresentationController? {
|
||||
let presentationController = ImageViewerTransitionPresentationController(
|
||||
presentedViewController: presented,
|
||||
presenting: presenting)
|
||||
return presentationController
|
||||
}
|
||||
|
||||
func animationController(
|
||||
forPresented presented: UIViewController,
|
||||
presenting: UIViewController,
|
||||
source: UIViewController
|
||||
) -> UIViewControllerAnimatedTransitioning? {
|
||||
|
||||
return ImageViewerTransitionPresentationAnimator(
|
||||
isPresenting: true, imageContentMode: imageContentMode)
|
||||
}
|
||||
|
||||
func animationController(
|
||||
forDismissed dismissed: UIViewController
|
||||
) -> UIViewControllerAnimatedTransitioning? {
|
||||
return ImageViewerTransitionPresentationAnimator(
|
||||
isPresenting: false, imageContentMode: imageContentMode)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIAdaptivePresentationControllerDelegate
|
||||
extension ImageViewerTransitionPresentationManager: UIAdaptivePresentationControllerDelegate {
|
||||
|
||||
func adaptivePresentationStyle(
|
||||
for controller: UIPresentationController,
|
||||
traitCollection: UITraitCollection
|
||||
) -> UIModalPresentationStyle {
|
||||
return .none
|
||||
}
|
||||
|
||||
func presentationController(
|
||||
_ controller: UIPresentationController,
|
||||
viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle
|
||||
) -> UIViewController? {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for ImageViewer_swift.
|
||||
FOUNDATION_EXPORT double ImageViewer_swiftVersionNumber;
|
||||
|
||||
//! Project version string for ImageViewer_swift.
|
||||
FOUNDATION_EXPORT const unsigned char ImageViewer_swiftVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <ImageViewer_swift/PublicHeader.h>
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
ImageViewer.swift
|
||||
|
||||
MIT
|
||||
|
||||
Copyright (c) 2013 Michael Henry Pantaleon (http://www.iamkel.net). All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,16 @@
|
||||
class SimpleImageDatasource:ImageDataSource {
|
||||
|
||||
private(set) var imageItems:[ImageItem]
|
||||
|
||||
init(imageItems: [ImageItem]) {
|
||||
self.imageItems = imageItems
|
||||
}
|
||||
|
||||
func numberOfImages() -> Int {
|
||||
return imageItems.count
|
||||
}
|
||||
|
||||
func imageItem(at index: Int) -> ImageItem {
|
||||
return imageItems[index]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
import UIKit
|
||||
|
||||
extension UIImageView {
|
||||
|
||||
// Data holder tap recognizer
|
||||
private class TapWithDataRecognizer:UITapGestureRecognizer {
|
||||
weak var from:UIViewController?
|
||||
var imageDatasource:ImageDataSource?
|
||||
var imageLoader:ImageLoader?
|
||||
var initialIndex:Int = 0
|
||||
var options:[ImageViewerOption] = []
|
||||
}
|
||||
|
||||
private var vc:UIViewController? {
|
||||
guard let rootVC = UIApplication.shared.keyWindow?.rootViewController
|
||||
else { return nil }
|
||||
return rootVC.presentedViewController != nil ? rootVC.presentedViewController : rootVC
|
||||
}
|
||||
|
||||
public func setupImageViewer(
|
||||
options:[ImageViewerOption] = [],
|
||||
from:UIViewController? = nil,
|
||||
imageLoader:ImageLoader? = nil) {
|
||||
setup(
|
||||
datasource: SimpleImageDatasource(imageItems: [.image(image)]),
|
||||
options: options,
|
||||
from: from,
|
||||
imageLoader: imageLoader)
|
||||
}
|
||||
|
||||
public func setupImageViewer(
|
||||
url:URL,
|
||||
initialIndex:Int = 0,
|
||||
placeholder: UIImage? = nil,
|
||||
options:[ImageViewerOption] = [],
|
||||
from:UIViewController? = nil,
|
||||
imageLoader:ImageLoader? = nil) {
|
||||
|
||||
let datasource = SimpleImageDatasource(
|
||||
imageItems: [url].compactMap {
|
||||
ImageItem.url($0, placeholder: placeholder)
|
||||
})
|
||||
setup(
|
||||
datasource: datasource,
|
||||
initialIndex: initialIndex,
|
||||
options: options,
|
||||
from: from,
|
||||
imageLoader: imageLoader)
|
||||
}
|
||||
|
||||
public func setupImageViewer(
|
||||
images:[UIImage],
|
||||
initialIndex:Int = 0,
|
||||
options:[ImageViewerOption] = [],
|
||||
from:UIViewController? = nil,
|
||||
imageLoader:ImageLoader? = nil) {
|
||||
|
||||
let datasource = SimpleImageDatasource(
|
||||
imageItems: images.compactMap {
|
||||
ImageItem.image($0)
|
||||
})
|
||||
setup(
|
||||
datasource: datasource,
|
||||
initialIndex: initialIndex,
|
||||
options: options,
|
||||
from: from,
|
||||
imageLoader: imageLoader)
|
||||
}
|
||||
|
||||
public func setupImageViewer(
|
||||
urls:[URL],
|
||||
initialIndex:Int = 0,
|
||||
options:[ImageViewerOption] = [],
|
||||
placeholder: UIImage? = nil,
|
||||
from:UIViewController? = nil,
|
||||
imageLoader:ImageLoader? = nil) {
|
||||
|
||||
let datasource = SimpleImageDatasource(
|
||||
imageItems: urls.compactMap {
|
||||
ImageItem.url($0, placeholder: placeholder)
|
||||
})
|
||||
setup(
|
||||
datasource: datasource,
|
||||
initialIndex: initialIndex,
|
||||
options: options,
|
||||
from: from,
|
||||
imageLoader: imageLoader)
|
||||
}
|
||||
|
||||
public func setupImageViewer(
|
||||
datasource:ImageDataSource,
|
||||
initialIndex:Int = 0,
|
||||
options:[ImageViewerOption] = [],
|
||||
from:UIViewController? = nil,
|
||||
imageLoader:ImageLoader? = nil) {
|
||||
|
||||
setup(
|
||||
datasource: datasource,
|
||||
initialIndex: initialIndex,
|
||||
options: options,
|
||||
from: from,
|
||||
imageLoader: imageLoader)
|
||||
}
|
||||
|
||||
private func setup(
|
||||
datasource:ImageDataSource?,
|
||||
initialIndex:Int = 0,
|
||||
options:[ImageViewerOption] = [],
|
||||
from: UIViewController? = nil,
|
||||
imageLoader:ImageLoader? = nil) {
|
||||
|
||||
var _tapRecognizer:TapWithDataRecognizer?
|
||||
gestureRecognizers?.forEach {
|
||||
if let _tr = $0 as? TapWithDataRecognizer {
|
||||
// if found, just use existing
|
||||
_tapRecognizer = _tr
|
||||
}
|
||||
}
|
||||
|
||||
isUserInteractionEnabled = true
|
||||
|
||||
var imageContentMode: UIView.ContentMode = .scaleAspectFill
|
||||
options.forEach {
|
||||
switch $0 {
|
||||
case .contentMode(let contentMode):
|
||||
imageContentMode = contentMode
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
contentMode = imageContentMode
|
||||
|
||||
clipsToBounds = true
|
||||
|
||||
if _tapRecognizer == nil {
|
||||
_tapRecognizer = TapWithDataRecognizer(
|
||||
target: self, action: #selector(showImageViewer(_:)))
|
||||
_tapRecognizer!.numberOfTouchesRequired = 1
|
||||
_tapRecognizer!.numberOfTapsRequired = 1
|
||||
}
|
||||
// Pass the Data
|
||||
_tapRecognizer!.imageDatasource = datasource
|
||||
_tapRecognizer!.imageLoader = imageLoader
|
||||
_tapRecognizer!.initialIndex = initialIndex
|
||||
_tapRecognizer!.options = options
|
||||
_tapRecognizer!.from = from
|
||||
addGestureRecognizer(_tapRecognizer!)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func showImageViewer(_ sender:TapWithDataRecognizer) {
|
||||
guard let sourceView = sender.view as? UIImageView else { return }
|
||||
let imageCarousel = ImageCarouselViewController.init(
|
||||
sourceView: sourceView,
|
||||
imageDataSource: sender.imageDatasource,
|
||||
imageLoader: sender.imageLoader ?? SDWebImageLoader(),
|
||||
options: sender.options,
|
||||
initialIndex: sender.initialIndex)
|
||||
let presentFromVC = sender.from ?? vc
|
||||
presentFromVC?.present(imageCarousel, animated: true)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import UIKit
|
||||
|
||||
extension UINavigationBar {
|
||||
|
||||
func insert(to view: UIView) {
|
||||
view.addSubview(self)
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
|
||||
rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
|
||||
topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
|
||||
.isActive = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import UIKit
|
||||
|
||||
extension UIView {
|
||||
func bindFrameToSuperview(top:CGFloat = 0, leading: CGFloat = 0, trailing:CGFloat = 0, bottom:CGFloat = 0) {
|
||||
guard let superview = self.superview else { return }
|
||||
self.translatesAutoresizingMaskIntoConstraints = false
|
||||
self.topAnchor.constraint(equalTo: superview.topAnchor, constant: top).isActive = true
|
||||
self.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: leading).isActive = true
|
||||
superview.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: trailing).isActive = true
|
||||
superview.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: bottom).isActive = true
|
||||
}
|
||||
|
||||
func bindFrameToSuperview(margin:CGFloat) {
|
||||
bindFrameToSuperview(top: margin, leading: margin, trailing: margin, bottom: margin)
|
||||
}
|
||||
|
||||
func frameRelativeToWindow() -> CGRect {
|
||||
return convert(bounds, to: nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOSApplicationExtension, unavailable)
|
||||
|
||||
extension View {
|
||||
|
||||
public func SPIndicator(
|
||||
isPresent: Binding<Bool>,
|
||||
indicatorView: SPIndicatorView,
|
||||
duration: TimeInterval = 2.0,
|
||||
haptic: SPIndicatorHaptic = .none
|
||||
) -> some View {
|
||||
|
||||
if isPresent.wrappedValue {
|
||||
let indicatorCompletion = indicatorView.completion
|
||||
let indicatorDismiss = {
|
||||
isPresent.wrappedValue = false
|
||||
indicatorCompletion?()
|
||||
}
|
||||
indicatorView.duration = duration
|
||||
indicatorView.present(haptic: haptic, completion: indicatorDismiss)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
public func SPIndicator(
|
||||
isPresent: Binding<Bool>,
|
||||
title: String = "",
|
||||
message: String? = nil,
|
||||
duration: TimeInterval = 2.0,
|
||||
presentSide: SPIndicatorPresentSide = .top,
|
||||
dismissByDrag: Bool = true,
|
||||
preset: SPIndicatorIconPreset = .done,
|
||||
haptic: SPIndicatorHaptic = .none,
|
||||
layout: SPIndicatorLayout? = nil,
|
||||
completion: (() -> Void)? = nil
|
||||
) -> some View {
|
||||
|
||||
let indicatorView = SPIndicatorView(title: title, message: message, preset: preset)
|
||||
indicatorView.presentSide = presentSide
|
||||
indicatorView.dismissByDrag = dismissByDrag
|
||||
indicatorView.layout = layout ?? SPIndicatorLayout(for: preset)
|
||||
indicatorView.completion = completion
|
||||
return SPIndicator(
|
||||
isPresent: isPresent, indicatorView: indicatorView, duration: duration, haptic: haptic)
|
||||
}
|
||||
|
||||
public func SPIndicator(
|
||||
isPresent: Binding<Bool>,
|
||||
title: String,
|
||||
duration: TimeInterval = 2.0,
|
||||
presentSide: SPIndicatorPresentSide = .top,
|
||||
dismissByDrag: Bool = true,
|
||||
preset: SPIndicatorIconPreset = .done,
|
||||
haptic: SPIndicatorHaptic = .none,
|
||||
completion: (() -> Void)? = nil
|
||||
) -> some View {
|
||||
|
||||
let indicatorView = SPIndicatorView(title: title, preset: preset)
|
||||
indicatorView.presentSide = presentSide
|
||||
indicatorView.dismissByDrag = dismissByDrag
|
||||
indicatorView.completion = completion
|
||||
return SPIndicator(
|
||||
isPresent: isPresent, indicatorView: indicatorView, duration: duration, haptic: haptic)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIColor {
|
||||
|
||||
enum Compability {
|
||||
|
||||
static var systemBackground: UIColor {
|
||||
|
||||
return UIColor.systemBackground
|
||||
|
||||
}
|
||||
|
||||
static var secondarySystemBackground: UIColor {
|
||||
|
||||
return UIColor.secondarySystemBackground
|
||||
|
||||
}
|
||||
|
||||
static var separator: UIColor {
|
||||
|
||||
return UIColor.separator
|
||||
|
||||
}
|
||||
|
||||
static var label: UIColor {
|
||||
|
||||
return UIColor.label
|
||||
|
||||
}
|
||||
|
||||
static var secondaryLabel: UIColor {
|
||||
|
||||
return UIColor.secondaryLabel
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static var buttonArea: UIColor {
|
||||
|
||||
return UIColor { (traits) -> UIColor in
|
||||
return traits.userInterfaceStyle == .dark
|
||||
? UIColor(red: 61 / 255, green: 62 / 255, blue: 66 / 255, alpha: 1)
|
||||
: UIColor(red: 238 / 255, green: 238 / 255, blue: 240 / 255, alpha: 1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@available(iOSApplicationExtension, unavailable)
|
||||
static var tint: UIColor {
|
||||
get {
|
||||
let value = UIApplication.shared.windows.first?.tintColor
|
||||
guard let tint = value else { return .systemBlue }
|
||||
return tint
|
||||
}
|
||||
set {
|
||||
UIApplication.shared.windows.forEach({ $0.tintColor = newValue })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIFont {
|
||||
|
||||
static func preferredFont(forTextStyle style: TextStyle, weight: Weight, addPoints: CGFloat = 0) -> UIFont {
|
||||
let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)
|
||||
let font = UIFont.systemFont(ofSize: descriptor.pointSize + addPoints, weight: weight)
|
||||
let metrics = UIFontMetrics(forTextStyle: style)
|
||||
return metrics.scaledFont(for: font)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UILabel {
|
||||
|
||||
func layoutDynamicHeight(width: CGFloat) {
|
||||
layoutDynamicHeight(x: frame.origin.x, y: frame.origin.y, width: width)
|
||||
}
|
||||
|
||||
func layoutDynamicHeight(x: CGFloat, y: CGFloat, width: CGFloat) {
|
||||
frame = CGRect.init(x: x, y: y, width: width, height: frame.height)
|
||||
sizeToFit()
|
||||
if frame.width != width {
|
||||
frame = .init(x: x, y: y, width: width, height: frame.height)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
public class SPIndicatorIconErrorView: UIView, SPIndicatorIconAnimatable {
|
||||
|
||||
public func animate() {
|
||||
animateTopToBottomLine()
|
||||
animateBottomToTopLine()
|
||||
}
|
||||
|
||||
private func animateTopToBottomLine() {
|
||||
let length = frame.width
|
||||
|
||||
let topToBottomLine = UIBezierPath()
|
||||
topToBottomLine.move(to: CGPoint(x: length * 0, y: length * 0))
|
||||
topToBottomLine.addLine(to: CGPoint(x: length * 1, y: length * 1))
|
||||
|
||||
let animatableLayer = CAShapeLayer()
|
||||
animatableLayer.path = topToBottomLine.cgPath
|
||||
animatableLayer.fillColor = UIColor.clear.cgColor
|
||||
animatableLayer.strokeColor = tintColor?.cgColor
|
||||
animatableLayer.lineWidth = 4
|
||||
animatableLayer.lineCap = .round
|
||||
animatableLayer.lineJoin = .round
|
||||
animatableLayer.strokeEnd = 0
|
||||
self.layer.addSublayer(animatableLayer)
|
||||
|
||||
let animation = CABasicAnimation(keyPath: "strokeEnd")
|
||||
animation.duration = 0.22
|
||||
animation.fromValue = 0
|
||||
animation.toValue = 1
|
||||
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
|
||||
animatableLayer.strokeEnd = 1
|
||||
animatableLayer.add(animation, forKey: "animation")
|
||||
}
|
||||
|
||||
private func animateBottomToTopLine() {
|
||||
let length = frame.width
|
||||
|
||||
let bottomToTopLine = UIBezierPath()
|
||||
bottomToTopLine.move(to: CGPoint(x: length * 0, y: length * 1))
|
||||
bottomToTopLine.addLine(to: CGPoint(x: length * 1, y: length * 0))
|
||||
|
||||
let animatableLayer = CAShapeLayer()
|
||||
animatableLayer.path = bottomToTopLine.cgPath
|
||||
animatableLayer.fillColor = UIColor.clear.cgColor
|
||||
animatableLayer.strokeColor = tintColor?.cgColor
|
||||
animatableLayer.lineWidth = 4
|
||||
animatableLayer.lineCap = .round
|
||||
animatableLayer.lineJoin = .round
|
||||
animatableLayer.strokeEnd = 0
|
||||
self.layer.addSublayer(animatableLayer)
|
||||
|
||||
let animation = CABasicAnimation(keyPath: "strokeEnd")
|
||||
animation.duration = 0.22
|
||||
animation.fromValue = 0
|
||||
animation.toValue = 1
|
||||
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
|
||||
animatableLayer.strokeEnd = 1
|
||||
animatableLayer.add(animation, forKey: "animation")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
public class SPIndicatorIconDoneView: UIView, SPIndicatorIconAnimatable {
|
||||
|
||||
public func animate() {
|
||||
let length = frame.width
|
||||
let animatablePath = UIBezierPath()
|
||||
animatablePath.move(to: CGPoint(x: length * 0.196, y: length * 0.527))
|
||||
animatablePath.addLine(to: CGPoint(x: length * 0.47, y: length * 0.777))
|
||||
animatablePath.addLine(to: CGPoint(x: length * 0.99, y: length * 0.25))
|
||||
|
||||
let animatableLayer = CAShapeLayer()
|
||||
animatableLayer.path = animatablePath.cgPath
|
||||
animatableLayer.fillColor = UIColor.clear.cgColor
|
||||
animatableLayer.strokeColor = tintColor?.cgColor
|
||||
animatableLayer.lineWidth = 4
|
||||
animatableLayer.lineCap = .round
|
||||
animatableLayer.lineJoin = .round
|
||||
animatableLayer.strokeEnd = 0
|
||||
layer.addSublayer(animatableLayer)
|
||||
|
||||
let animation = CABasicAnimation(keyPath: "strokeEnd")
|
||||
animation.duration = 0.25
|
||||
animation.fromValue = 0
|
||||
animation.toValue = 1
|
||||
animation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
||||
animatableLayer.strokeEnd = 1
|
||||
animatableLayer.add(animation, forKey: "animation")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Ivan Vorobei
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,43 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
/**
|
||||
SPIndicator: Layout model for view.
|
||||
*/
|
||||
open class SPIndicatorLayout {
|
||||
|
||||
/**
|
||||
SPIndicator: Icon size.
|
||||
*/
|
||||
open var iconSize: CGSize
|
||||
|
||||
/**
|
||||
SPIndicator: Alert margings for each side.
|
||||
*/
|
||||
open var margins: UIEdgeInsets
|
||||
|
||||
public init(iconSize: CGSize, margins: UIEdgeInsets) {
|
||||
self.iconSize = iconSize
|
||||
self.margins = margins
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
SPIndicator: Cases from preset styles.
|
||||
*/
|
||||
public enum SPIndicatorPresentSide {
|
||||
|
||||
case top
|
||||
case center
|
||||
case bottom
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
/**
|
||||
SPIndicator: Protocol for animatable views.
|
||||
*/
|
||||
public protocol SPIndicatorIconAnimatable {
|
||||
|
||||
/**
|
||||
SPIndicator: Shoud call when need start animation.
|
||||
*/
|
||||
func animate()
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
@available(iOSApplicationExtension, unavailable)
|
||||
public enum SPIndicator {
|
||||
|
||||
/**
|
||||
SPIndicator: Present alert with preset and custom haptic.
|
||||
|
||||
- parameter title: Title text in alert.
|
||||
- parameter message: Subtitle text in alert. Optional.
|
||||
- parameter preset: Icon ready-use style or custom image.
|
||||
- parameter haptic: Haptic response with present. Default is `.success`.
|
||||
- parameter presentSide: Choose from side appear indicator.
|
||||
- parameter completion: Will call with dismiss alert.
|
||||
*/
|
||||
public static func present(
|
||||
title: String, message: String? = nil, preset: SPIndicatorIconPreset,
|
||||
haptic: SPIndicatorHaptic, from presentSide: SPIndicatorPresentSide = .top,
|
||||
completion: (() -> Void)? = nil
|
||||
) {
|
||||
let alertView = SPIndicatorView(title: title, message: message, preset: preset)
|
||||
alertView.presentSide = presentSide
|
||||
alertView.present(haptic: haptic, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
SPIndicator: Present alert with preset and automatically detect type haptic.
|
||||
|
||||
- parameter title: Title text in alert.
|
||||
- parameter message: Subtitle text in alert. Optional.
|
||||
- parameter preset: Icon ready-use style or custom image.
|
||||
- parameter presentSide: Choose from side appear indicator. Default is `.top`.
|
||||
- parameter completion: Will call with dismiss alert.
|
||||
*/
|
||||
public static func present(
|
||||
title: String, message: String? = nil, preset: SPIndicatorIconPreset,
|
||||
from presentSide: SPIndicatorPresentSide = .top, completion: (() -> Void)? = nil
|
||||
) {
|
||||
let alertView = SPIndicatorView(title: title, message: message, preset: preset)
|
||||
alertView.presentSide = presentSide
|
||||
let haptic = preset.getHaptic()
|
||||
alertView.present(haptic: haptic, completion: completion)
|
||||
}
|
||||
|
||||
/**
|
||||
SPIndicator: Show only message, without title and icon.
|
||||
|
||||
- parameter message: Title text.
|
||||
- parameter haptic: Haptic response with present. Default is `.success`.
|
||||
- parameter presentSide: Choose from side appear indicator. Default is `.top`.
|
||||
- parameter completion: Will call with dismiss alert.
|
||||
*/
|
||||
public static func present(
|
||||
title: String, message: String? = nil, haptic: SPIndicatorHaptic,
|
||||
from presentSide: SPIndicatorPresentSide = .top, completion: (() -> Void)? = nil
|
||||
) {
|
||||
let alertView = SPIndicatorView(title: title, message: message)
|
||||
alertView.presentSide = presentSide
|
||||
alertView.present(haptic: haptic, completion: completion)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
/**
|
||||
SPIndicator: Represent icon wrapper.
|
||||
Included default styles and can be custom image.
|
||||
*/
|
||||
public enum SPIndicatorIconPreset {
|
||||
|
||||
case done
|
||||
case error
|
||||
case spin(_ style: UIActivityIndicatorView.Style)
|
||||
case custom(_ image: UIImage)
|
||||
}
|
||||
|
||||
// Get view and haptic by Preset.
|
||||
|
||||
public extension SPIndicatorIconPreset {
|
||||
|
||||
func createView() -> UIView {
|
||||
switch self {
|
||||
case .done:
|
||||
let view = SPIndicatorIconDoneView()
|
||||
view.tintColor = .systemBlue
|
||||
return view
|
||||
case .error:
|
||||
let view = SPIndicatorIconErrorView()
|
||||
view.tintColor = UIColor.systemRed
|
||||
return view
|
||||
case .spin(let style):
|
||||
let view = UIActivityIndicatorView(style: style)
|
||||
view.startAnimating()
|
||||
return view
|
||||
case .custom(let image):
|
||||
let imageView = UIImageView(image: image)
|
||||
imageView.contentMode = .scaleAspectFit
|
||||
return imageView
|
||||
}
|
||||
}
|
||||
|
||||
func getHaptic() -> SPIndicatorHaptic {
|
||||
switch self {
|
||||
case .error: return .error
|
||||
case .done: return .success
|
||||
case .spin(_): return .none
|
||||
case .custom(_): return .success
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get layout by preset.
|
||||
|
||||
public extension SPIndicatorLayout {
|
||||
|
||||
convenience init() {
|
||||
self.init(
|
||||
iconSize: .init(
|
||||
width: Self.defaultIconSideSize,
|
||||
height: Self.defaultIconSideSize
|
||||
),
|
||||
margins: .init(
|
||||
top: Self.defaultVerticallInset,
|
||||
left: Self.defaultHorizontalInset,
|
||||
bottom: Self.defaultVerticallInset,
|
||||
right: Self.defaultHorizontalInset
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
static func message() -> SPIndicatorLayout {
|
||||
let layout = SPIndicatorLayout()
|
||||
return layout
|
||||
}
|
||||
|
||||
convenience init(for preset: SPIndicatorIconPreset) {
|
||||
switch preset {
|
||||
case .done:
|
||||
self.init()
|
||||
iconSize = .init(width: 24, height: 24)
|
||||
case .error:
|
||||
self.init()
|
||||
iconSize = .init(width: 14, height: 14)
|
||||
margins.left = 19
|
||||
margins.right = margins.left
|
||||
case .spin(_):
|
||||
self.init()
|
||||
case .custom(_):
|
||||
self.init()
|
||||
}
|
||||
}
|
||||
|
||||
// Default values.
|
||||
|
||||
private static var defaultIconSideSize: CGFloat { 28 }
|
||||
private static var defaultSpaceBetweenIconAndTitle: CGFloat { 26 }
|
||||
private static var defaultVerticallInset: CGFloat { 8 }
|
||||
private static var defaultHorizontalInset: CGFloat { 15 }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,654 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
/// SPIndicator: Main view. Can be customisable if need.
|
||||
///
|
||||
/// For change duration, check method `present` and pass duration and other specific property if need customise.
|
||||
///
|
||||
/// Here available set window on which shoud be present.
|
||||
/// If you have some windows, you shoud configure it. Check property `presentWindow`.
|
||||
///
|
||||
/// For disable dismiss by drag, check property `.dismissByDrag`.
|
||||
///
|
||||
/// Recomended call `SPIndicator` and choose style func.
|
||||
@available(iOSApplicationExtension, unavailable)
|
||||
open class SPIndicatorView: UIView {
|
||||
|
||||
// MARK: - UIAppearance
|
||||
|
||||
@objc dynamic open var duration: TimeInterval = 1.5
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
/**
|
||||
SPIndicator: Change it for set `top` or `bottom` present side.
|
||||
Shoud be change before present, instead of no effect.
|
||||
*/
|
||||
open var presentSide: SPIndicatorPresentSide = .top
|
||||
|
||||
/**
|
||||
SPIndicator: By default allow drag indicator for hide.
|
||||
While indicator is dragging, dismiss not work.
|
||||
This behaviar can be disabled.
|
||||
*/
|
||||
open var dismissByDrag: Bool = true {
|
||||
didSet {
|
||||
setGesture()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
SPIndicator: Completion call after hide indicator.
|
||||
*/
|
||||
open var completion: (() -> Void)? = nil
|
||||
|
||||
// MARK: - Views
|
||||
|
||||
open var titleLabel: UILabel?
|
||||
open var subtitleLabel: UILabel?
|
||||
open var iconView: UIView?
|
||||
|
||||
private lazy var backgroundView: UIVisualEffectView = {
|
||||
let view: UIVisualEffectView = {
|
||||
if #available(iOS 13.0, *) {
|
||||
return UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial))
|
||||
} else {
|
||||
return UIVisualEffectView(effect: UIBlurEffect(style: .light))
|
||||
}
|
||||
}()
|
||||
view.isUserInteractionEnabled = false
|
||||
return view
|
||||
}()
|
||||
|
||||
weak open var presentWindow: UIWindow?
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
public init(title: String, message: String? = nil, preset: SPIndicatorIconPreset) {
|
||||
super.init(frame: CGRect.zero)
|
||||
commonInit()
|
||||
layout = SPIndicatorLayout(for: preset)
|
||||
setTitle(title)
|
||||
if let message = message {
|
||||
setMessage(message)
|
||||
}
|
||||
setIcon(for: preset)
|
||||
}
|
||||
|
||||
public init(title: String, message: String?) {
|
||||
super.init(frame: CGRect.zero)
|
||||
titleAreaFactor = 1.8
|
||||
minimumAreaWidth = 100
|
||||
commonInit()
|
||||
layout = SPIndicatorLayout.message()
|
||||
setTitle(title)
|
||||
if let message = message {
|
||||
setMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
self.presentSide = .top
|
||||
super.init(coder: aDecoder)
|
||||
commonInit()
|
||||
}
|
||||
|
||||
private func commonInit() {
|
||||
preservesSuperviewLayoutMargins = false
|
||||
insetsLayoutMarginsFromSafeArea = false
|
||||
|
||||
backgroundColor = .clear
|
||||
backgroundView.layer.masksToBounds = true
|
||||
addSubview(backgroundView)
|
||||
|
||||
setShadow()
|
||||
setGesture()
|
||||
}
|
||||
|
||||
// MARK: - Configure
|
||||
|
||||
private func setTitle(_ text: String) {
|
||||
let label = UILabel()
|
||||
label.font = UIFont.preferredFont(
|
||||
forTextStyle: .footnote, weight: .semibold, addPoints: 0)
|
||||
label.numberOfLines = 1
|
||||
let style = NSMutableParagraphStyle()
|
||||
style.lineBreakMode = .byTruncatingTail
|
||||
style.lineSpacing = 3
|
||||
label.attributedText = NSAttributedString(
|
||||
string: text, attributes: [.paragraphStyle: style]
|
||||
)
|
||||
label.textAlignment = .center
|
||||
label.textColor = UIColor.Compability.label
|
||||
titleLabel = label
|
||||
addSubview(label)
|
||||
}
|
||||
|
||||
private func setMessage(_ text: String) {
|
||||
let label = UILabel()
|
||||
label.font = UIFont.preferredFont(
|
||||
forTextStyle: .footnote, weight: .semibold, addPoints: 0)
|
||||
label.numberOfLines = 3
|
||||
let style = NSMutableParagraphStyle()
|
||||
style.lineBreakMode = .byTruncatingTail
|
||||
style.lineSpacing = 2
|
||||
label.attributedText = NSAttributedString(
|
||||
string: text, attributes: [.paragraphStyle: style]
|
||||
)
|
||||
label.textAlignment = .center
|
||||
label.textColor = UIColor.Compability.label.withAlphaComponent(0.8)
|
||||
subtitleLabel = label
|
||||
addSubview(label)
|
||||
}
|
||||
|
||||
private func setIcon(for preset: SPIndicatorIconPreset) {
|
||||
let view = preset.createView()
|
||||
self.iconView = view
|
||||
addSubview(view)
|
||||
}
|
||||
|
||||
private func setShadow() {
|
||||
layer.shadowColor = UIColor.black.cgColor
|
||||
layer.shadowOpacity = 0.22
|
||||
layer.shadowOffset = .init(width: 0, height: 7)
|
||||
layer.shadowRadius = 40
|
||||
|
||||
// Not use render shadow becouse backgorund is visual effect.
|
||||
// If turn on it, background will hide.
|
||||
// layer.shouldRasterize = true
|
||||
}
|
||||
|
||||
private func setGesture() {
|
||||
if dismissByDrag {
|
||||
let gestureRecognizer = UIPanGestureRecognizer(
|
||||
target: self, action: #selector(handlePan))
|
||||
addGestureRecognizer(gestureRecognizer)
|
||||
self.gestureRecognizer = gestureRecognizer
|
||||
} else {
|
||||
self.gestureRecognizer = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Present
|
||||
|
||||
private var presentAndDismissDuration: TimeInterval = 0.6
|
||||
|
||||
private var presentWithOpacity: Bool {
|
||||
if presentSide == .center { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
open func present(haptic: SPIndicatorHaptic = .success, completion: (() -> Void)? = nil) {
|
||||
present(duration: self.duration, haptic: haptic, completion: completion)
|
||||
}
|
||||
|
||||
open func present(
|
||||
duration: TimeInterval, haptic: SPIndicatorHaptic = .success,
|
||||
completion: (() -> Void)? = nil
|
||||
) {
|
||||
|
||||
if self.presentWindow == nil {
|
||||
self.presentWindow = UIApplication.shared.keyWindow
|
||||
}
|
||||
|
||||
guard let window = self.presentWindow else { return }
|
||||
|
||||
window.addSubview(self)
|
||||
|
||||
// Prepare for present
|
||||
|
||||
self.whenGestureEndShoudHide = false
|
||||
self.completion = completion
|
||||
|
||||
isHidden = true
|
||||
sizeToFit()
|
||||
layoutSubviews()
|
||||
center.x = window.frame.midX
|
||||
toPresentPosition(.prepare(presentSide))
|
||||
|
||||
self.alpha = presentWithOpacity ? 0 : 1
|
||||
|
||||
// Present
|
||||
|
||||
isHidden = false
|
||||
haptic.impact()
|
||||
UIView.animate(
|
||||
withDuration: presentAndDismissDuration, delay: 0, usingSpringWithDamping: 1,
|
||||
initialSpringVelocity: 0, options: [.beginFromCurrentState, .curveEaseOut],
|
||||
animations: {
|
||||
self.toPresentPosition(.visible(self.presentSide))
|
||||
if self.presentWithOpacity { self.alpha = 1 }
|
||||
},
|
||||
completion: { finished in
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
|
||||
if self.gestureIsDragging {
|
||||
self.whenGestureEndShoudHide = true
|
||||
} else {
|
||||
self.dismiss()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if let iconView = self.iconView as? SPIndicatorIconAnimatable {
|
||||
DispatchQueue.main.asyncAfter(
|
||||
deadline: DispatchTime.now() + presentAndDismissDuration / 3
|
||||
) {
|
||||
iconView.animate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc open func dismiss() {
|
||||
UIView.animate(
|
||||
withDuration: presentAndDismissDuration, delay: 0, usingSpringWithDamping: 1,
|
||||
initialSpringVelocity: 0, options: [.beginFromCurrentState, .curveEaseIn],
|
||||
animations: {
|
||||
self.toPresentPosition(.prepare(self.presentSide))
|
||||
if self.presentWithOpacity { self.alpha = 0 }
|
||||
},
|
||||
completion: { finished in
|
||||
self.removeFromSuperview()
|
||||
self.completion?()
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
private var minimumYTranslationForHideByGesture: CGFloat = -10
|
||||
private var maximumYTranslationByGesture: CGFloat = 60
|
||||
|
||||
private var gestureRecognizer: UIPanGestureRecognizer?
|
||||
private var gestureIsDragging: Bool = false
|
||||
private var whenGestureEndShoudHide: Bool = false
|
||||
|
||||
@objc func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
|
||||
|
||||
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
|
||||
self.gestureIsDragging = true
|
||||
let translation = gestureRecognizer.translation(in: self)
|
||||
let newTranslation: CGFloat = {
|
||||
switch presentSide {
|
||||
case .top:
|
||||
if translation.y <= 0 {
|
||||
return translation.y
|
||||
} else {
|
||||
return min(maximumYTranslationByGesture, translation.y.squareRoot())
|
||||
}
|
||||
case .bottom:
|
||||
if translation.y >= 0 {
|
||||
return translation.y
|
||||
} else {
|
||||
let absolute = abs(translation.y)
|
||||
return -min(maximumYTranslationByGesture, absolute.squareRoot())
|
||||
}
|
||||
case .center:
|
||||
let absolute = abs(translation.y).squareRoot()
|
||||
let newValue = translation.y < 0 ? -absolute : absolute
|
||||
return min(maximumYTranslationByGesture, newValue)
|
||||
}
|
||||
}()
|
||||
toPresentPosition(.fromVisible(newTranslation, from: (presentSide)))
|
||||
}
|
||||
|
||||
if gestureRecognizer.state == .ended {
|
||||
gestureIsDragging = false
|
||||
|
||||
var shoudDismissWhenEndAnimation: Bool = false
|
||||
|
||||
UIView.animate(
|
||||
withDuration: presentAndDismissDuration, delay: 0, usingSpringWithDamping: 1,
|
||||
initialSpringVelocity: 0, options: [.beginFromCurrentState, .curveEaseIn],
|
||||
animations: {
|
||||
if self.whenGestureEndShoudHide {
|
||||
self.toPresentPosition(.prepare(self.presentSide))
|
||||
shoudDismissWhenEndAnimation = true
|
||||
} else {
|
||||
let translation = gestureRecognizer.translation(in: self)
|
||||
if translation.y < self.minimumYTranslationForHideByGesture {
|
||||
self.toPresentPosition(.prepare(self.presentSide))
|
||||
shoudDismissWhenEndAnimation = true
|
||||
} else {
|
||||
self.toPresentPosition(.visible(self.presentSide))
|
||||
}
|
||||
}
|
||||
},
|
||||
completion: { _ in
|
||||
if shoudDismissWhenEndAnimation {
|
||||
self.dismiss()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func toPresentPosition(_ position: PresentPosition) {
|
||||
|
||||
let getPrepareTransform: ((_ side: SPIndicatorPresentSide) -> CGAffineTransform) = {
|
||||
[weak self] side in
|
||||
guard let self = self else { return .identity }
|
||||
guard let window = UIApplication.shared.windows.first else { return .identity }
|
||||
switch side {
|
||||
case .top:
|
||||
let topInset = window.safeAreaInsets.top
|
||||
let position = -(topInset + 50)
|
||||
return CGAffineTransform.identity.translatedBy(x: 0, y: position)
|
||||
case .bottom:
|
||||
let height = window.frame.height
|
||||
let bottomInset = window.safeAreaInsets.bottom
|
||||
let position = height + bottomInset + 50
|
||||
return CGAffineTransform.identity.translatedBy(x: 0, y: position)
|
||||
case .center:
|
||||
return CGAffineTransform.identity.translatedBy(
|
||||
x: 0, y: window.frame.height / 2 - self.frame.height / 2
|
||||
).scaledBy(x: 0.9, y: 0.9)
|
||||
}
|
||||
}
|
||||
|
||||
let getVisibleTransform: ((_ side: SPIndicatorPresentSide) -> CGAffineTransform) = {
|
||||
[weak self] side in
|
||||
guard let self = self else { return .identity }
|
||||
guard let window = UIApplication.shared.windows.first else { return .identity }
|
||||
switch side {
|
||||
case .top:
|
||||
var topSafeAreaInsets = window.safeAreaInsets.top
|
||||
if topSafeAreaInsets < 20 { topSafeAreaInsets = 20 }
|
||||
let position = topSafeAreaInsets - 3 + self.offset
|
||||
return CGAffineTransform.identity.translatedBy(x: 0, y: position)
|
||||
case .bottom:
|
||||
let height = window.frame.height
|
||||
var bottomSafeAreaInsets = window.safeAreaInsets.top
|
||||
if bottomSafeAreaInsets < 20 { bottomSafeAreaInsets = 20 }
|
||||
let position =
|
||||
height - bottomSafeAreaInsets - 3 - self.frame.height - self.offset
|
||||
return CGAffineTransform.identity.translatedBy(x: 0, y: position)
|
||||
case .center:
|
||||
return CGAffineTransform.identity.translatedBy(
|
||||
x: 0, y: window.frame.height / 2 - self.frame.height / 2)
|
||||
}
|
||||
}
|
||||
|
||||
switch position {
|
||||
case .prepare(let presentSide):
|
||||
transform = getPrepareTransform(presentSide)
|
||||
case .visible(let presentSide):
|
||||
transform = getVisibleTransform(presentSide)
|
||||
case .fromVisible(let translation, let presentSide):
|
||||
transform = getVisibleTransform(presentSide).translatedBy(x: 0, y: translation)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Layout
|
||||
|
||||
/**
|
||||
SPIndicator: Wraper of layout values.
|
||||
*/
|
||||
open var layout: SPIndicatorLayout = .init()
|
||||
|
||||
/**
|
||||
SPIndicator: Alert offset
|
||||
*/
|
||||
open var offset: CGFloat = 0
|
||||
|
||||
private var minimumAreaHeight: CGFloat = 50
|
||||
private var minimumAreaWidth: CGFloat = 196
|
||||
private var maximumAreaWidth: CGFloat = 260
|
||||
private var titleAreaFactor: CGFloat = 2.5
|
||||
private var spaceBetweenTitles: CGFloat = 1
|
||||
private var spaceBetweenTitlesAndImage: CGFloat = 16
|
||||
|
||||
private var titlesCompactWidth: CGFloat {
|
||||
if let iconView = self.iconView {
|
||||
let space = iconView.frame.maxY + spaceBetweenTitlesAndImage
|
||||
return frame.width - space * 2
|
||||
} else {
|
||||
return frame.width - layoutMargins.left - layoutMargins.right
|
||||
}
|
||||
}
|
||||
|
||||
private var titlesFullWidth: CGFloat {
|
||||
if let iconView = self.iconView {
|
||||
let space = iconView.frame.maxY + spaceBetweenTitlesAndImage
|
||||
return frame.width - space - layoutMargins.right - self.spaceBetweenTitlesAndImage
|
||||
} else {
|
||||
return frame.width - layoutMargins.left - layoutMargins.right
|
||||
}
|
||||
}
|
||||
|
||||
open override func sizeThatFits(_ size: CGSize) -> CGSize {
|
||||
var width = minimumAreaWidth
|
||||
|
||||
// First determine the width we'll use
|
||||
titleLabel?.sizeToFit()
|
||||
let titleWidth: CGFloat = titleLabel?.frame.width ?? 0
|
||||
|
||||
subtitleLabel?.sizeToFit()
|
||||
let subtitleWidth: CGFloat = subtitleLabel?.frame.width ?? 0
|
||||
|
||||
width = (max(titleWidth, subtitleWidth) * titleAreaFactor).rounded()
|
||||
|
||||
if width < minimumAreaWidth { width = minimumAreaWidth }
|
||||
if width > maximumAreaWidth { width = maximumAreaWidth }
|
||||
|
||||
// Now calculate heights based on this width
|
||||
let availableTextWidth = width - layoutMargins.left - layoutMargins.right
|
||||
|
||||
var titleHeight: CGFloat = 0
|
||||
if let titleLabel = titleLabel {
|
||||
titleLabel.frame.size.width = availableTextWidth
|
||||
titleLabel.sizeToFit()
|
||||
titleHeight = titleLabel.frame.height
|
||||
}
|
||||
|
||||
var subtitleHeight: CGFloat = 0
|
||||
if let subtitleLabel = subtitleLabel {
|
||||
subtitleLabel.frame.size.width = availableTextWidth
|
||||
subtitleLabel.sizeToFit()
|
||||
subtitleHeight = subtitleLabel.frame.height
|
||||
}
|
||||
|
||||
// Calculate dynamic height based on content
|
||||
var height: CGFloat = 0
|
||||
if titleLabel != nil && subtitleLabel != nil {
|
||||
height =
|
||||
titleHeight + subtitleHeight + spaceBetweenTitles + layoutMargins.top
|
||||
+ layoutMargins.bottom
|
||||
} else if titleLabel != nil {
|
||||
height = titleHeight + layoutMargins.top + layoutMargins.bottom
|
||||
} else if subtitleLabel != nil {
|
||||
height = subtitleHeight + layoutMargins.top + layoutMargins.bottom
|
||||
}
|
||||
|
||||
// Ensure minimum height
|
||||
if height < minimumAreaHeight {
|
||||
height = minimumAreaHeight
|
||||
}
|
||||
|
||||
return .init(width: width, height: height)
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
layoutMargins = layout.margins
|
||||
layer.cornerRadius = frame.height / 2
|
||||
backgroundView.frame = bounds
|
||||
backgroundView.layer.cornerRadius = layer.cornerRadius
|
||||
|
||||
// Flags
|
||||
|
||||
let hasIcon = (self.iconView != nil)
|
||||
let hasTitle = (self.titleLabel != nil)
|
||||
let hasSubtite = (self.subtitleLabel != nil)
|
||||
|
||||
let fitTitleToCompact: Bool = {
|
||||
guard let titleLabel = self.titleLabel else { return true }
|
||||
titleLabel.numberOfLines = 1
|
||||
titleLabel.sizeToFit()
|
||||
return titleLabel.frame.width < titlesCompactWidth
|
||||
}()
|
||||
|
||||
let fitSubtitleToCompact: Bool = {
|
||||
guard let subtitleLabel = self.subtitleLabel else { return true }
|
||||
let originalLines = subtitleLabel.numberOfLines
|
||||
subtitleLabel.sizeToFit()
|
||||
subtitleLabel.numberOfLines = originalLines
|
||||
return subtitleLabel.frame.width < titlesCompactWidth
|
||||
}()
|
||||
|
||||
let notFitAnyLabelToCompact: Bool = {
|
||||
if !fitTitleToCompact { return true }
|
||||
if !fitSubtitleToCompact { return true }
|
||||
return false
|
||||
}()
|
||||
|
||||
var layout: LayoutGrid = .iconTitleCentered
|
||||
|
||||
if (hasIcon && hasTitle && hasSubtite) && !notFitAnyLabelToCompact {
|
||||
layout = .iconTitleMessageCentered
|
||||
}
|
||||
|
||||
if (hasIcon && hasTitle && hasSubtite) && notFitAnyLabelToCompact {
|
||||
layout = .iconTitleMessageLeading
|
||||
}
|
||||
|
||||
if hasIcon && hasTitle && !hasSubtite {
|
||||
layout = .iconTitleCentered
|
||||
}
|
||||
|
||||
if !hasIcon && hasTitle && !hasSubtite {
|
||||
layout = .title
|
||||
}
|
||||
|
||||
if !hasIcon && hasTitle && hasSubtite {
|
||||
layout = .titleMessage
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
let layoutIcon = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
guard let iconView = self.iconView else { return }
|
||||
iconView.frame = .init(
|
||||
origin: .init(x: self.layoutMargins.left, y: iconView.frame.origin.y),
|
||||
size: self.layout.iconSize
|
||||
)
|
||||
iconView.center.y = self.bounds.midY
|
||||
}
|
||||
|
||||
let layoutTitleCenteredCompact = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
guard let titleLabel = self.titleLabel else { return }
|
||||
titleLabel.textAlignment = .center
|
||||
titleLabel.layoutDynamicHeight(width: self.titlesCompactWidth)
|
||||
titleLabel.center.x = self.frame.width / 2
|
||||
}
|
||||
|
||||
let layoutTitleCenteredFullWidth = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
guard let titleLabel = self.titleLabel else { return }
|
||||
titleLabel.textAlignment = .center
|
||||
titleLabel.layoutDynamicHeight(width: self.titlesFullWidth)
|
||||
titleLabel.center.x = self.frame.width / 2
|
||||
}
|
||||
|
||||
let layoutTitleLeadingFullWidth = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
guard let titleLabel = self.titleLabel else { return }
|
||||
guard let iconView = self.iconView else { return }
|
||||
let rtl = self.effectiveUserInterfaceLayoutDirection == .rightToLeft
|
||||
titleLabel.textAlignment = rtl ? .right : .left
|
||||
titleLabel.layoutDynamicHeight(width: self.titlesFullWidth)
|
||||
titleLabel.frame.origin.x =
|
||||
self.layoutMargins.left + iconView.frame.width + self.spaceBetweenTitlesAndImage
|
||||
}
|
||||
|
||||
let layoutSubtitle = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
guard let titleLabel = self.titleLabel else { return }
|
||||
guard let subtitleLabel = self.subtitleLabel else { return }
|
||||
subtitleLabel.textAlignment = titleLabel.textAlignment
|
||||
subtitleLabel.layoutDynamicHeight(width: titleLabel.frame.width)
|
||||
subtitleLabel.frame.origin.x = titleLabel.frame.origin.x
|
||||
}
|
||||
|
||||
let layoutTitleSubtitleByVertical = { [weak self] in
|
||||
guard let self = self else { return }
|
||||
guard let titleLabel = self.titleLabel else { return }
|
||||
guard let subtitleLabel = self.subtitleLabel else {
|
||||
titleLabel.center.y = self.bounds.midY
|
||||
return
|
||||
}
|
||||
let allHeight =
|
||||
titleLabel.frame.height + subtitleLabel.frame.height + self.spaceBetweenTitles
|
||||
titleLabel.frame.origin.y = (self.frame.height - allHeight) / 2
|
||||
subtitleLabel.frame.origin.y = titleLabel.frame.maxY + self.spaceBetweenTitles
|
||||
}
|
||||
|
||||
// Apply
|
||||
|
||||
switch layout {
|
||||
case .iconTitleMessageCentered:
|
||||
layoutIcon()
|
||||
layoutTitleCenteredCompact()
|
||||
layoutSubtitle()
|
||||
case .iconTitleMessageLeading:
|
||||
layoutIcon()
|
||||
layoutTitleLeadingFullWidth()
|
||||
layoutSubtitle()
|
||||
case .iconTitleCentered:
|
||||
layoutIcon()
|
||||
titleLabel?.numberOfLines = 2
|
||||
layoutTitleCenteredCompact()
|
||||
case .iconTitleLeading:
|
||||
layoutIcon()
|
||||
titleLabel?.numberOfLines = 2
|
||||
layoutTitleLeadingFullWidth()
|
||||
case .title:
|
||||
titleLabel?.numberOfLines = 2
|
||||
layoutTitleCenteredFullWidth()
|
||||
case .titleMessage:
|
||||
layoutTitleCenteredFullWidth()
|
||||
layoutSubtitle()
|
||||
}
|
||||
|
||||
layoutTitleSubtitleByVertical()
|
||||
}
|
||||
|
||||
// MARK: - Models
|
||||
|
||||
enum PresentPosition {
|
||||
|
||||
case prepare(_ from: SPIndicatorPresentSide)
|
||||
case visible(_ from: SPIndicatorPresentSide)
|
||||
case fromVisible(_ translation: CGFloat, from: SPIndicatorPresentSide)
|
||||
}
|
||||
|
||||
enum LayoutGrid {
|
||||
|
||||
case iconTitleMessageCentered
|
||||
case iconTitleMessageLeading
|
||||
case iconTitleCentered
|
||||
case iconTitleLeading
|
||||
case title
|
||||
case titleMessage
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// The MIT License (MIT)
|
||||
// Copyright © 2021 Ivan Vorobei (hello@ivanvorobei.io)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import UIKit
|
||||
|
||||
/// SPIndicator: Wrapper of haptic styles.
|
||||
public enum SPIndicatorHaptic {
|
||||
|
||||
case success
|
||||
case warning
|
||||
case error
|
||||
case none
|
||||
|
||||
func impact() {
|
||||
|
||||
let generator = UINotificationFeedbackGenerator()
|
||||
switch self {
|
||||
case .success:
|
||||
generator.notificationOccurred(UINotificationFeedbackGenerator.FeedbackType.success)
|
||||
case .warning:
|
||||
generator.notificationOccurred(UINotificationFeedbackGenerator.FeedbackType.warning)
|
||||
case .error:
|
||||
generator.notificationOccurred(UINotificationFeedbackGenerator.FeedbackType.error)
|
||||
case .none:
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@
|
||||
"peerDependencies": {
|
||||
"expo": "52.0.35",
|
||||
"react": "18.3.1",
|
||||
"react-native": "0.77.0"
|
||||
"react-native": "0.77.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"expo-module-scripts": "4.0.4"
|
||||
|
||||
+44
-40
@@ -15,8 +15,8 @@
|
||||
"web": "expo start --web"
|
||||
},
|
||||
"dependencies": {
|
||||
"@better-auth/expo": "1.1.18",
|
||||
"@expo/react-native-action-sheet": "4.1.0",
|
||||
"@better-auth/expo": "1.2.4",
|
||||
"@expo/react-native-action-sheet": "4.1.1",
|
||||
"@expo/vector-icons": "14.0.4",
|
||||
"@follow/components": "workspace:*",
|
||||
"@follow/constants": "workspace:*",
|
||||
@@ -24,31 +24,33 @@
|
||||
"@follow/models": "workspace:*",
|
||||
"@follow/shared": "workspace:*",
|
||||
"@follow/utils": "workspace:*",
|
||||
"@hookform/resolvers": "4.1.0",
|
||||
"@hookform/resolvers": "4.1.3",
|
||||
"@react-native-community/image-editor": "4.3.0",
|
||||
"@react-native-firebase/analytics": "21.12.0",
|
||||
"@react-native-firebase/app": "21.12.0",
|
||||
"@react-native-firebase/app-check": "21.12.0",
|
||||
"@react-native-firebase/crashlytics": "21.12.0",
|
||||
"@react-native-picker/picker": "2.9.0",
|
||||
"@react-navigation/bottom-tabs": "7.2.0",
|
||||
"@react-navigation/drawer": "7.1.1",
|
||||
"@react-navigation/native": "7.0.14",
|
||||
"@react-native-picker/picker": "2.11.0",
|
||||
"@react-navigation/bottom-tabs": "7.2.1",
|
||||
"@react-navigation/drawer": "7.1.2",
|
||||
"@react-navigation/native": "7.0.15",
|
||||
"@shopify/flash-list": "1.7.3",
|
||||
"@tanstack/query-sync-storage-persister": "5.66.4",
|
||||
"@tanstack/react-query": "5.66.7",
|
||||
"@tanstack/react-query-persist-client": "5.66.7",
|
||||
"better-auth": "1.1.18",
|
||||
"cookie-es": "1.2.2",
|
||||
"@tanstack/query-sync-storage-persister": "5.67.3",
|
||||
"@tanstack/react-query": "5.67.3",
|
||||
"@tanstack/react-query-persist-client": "5.67.3",
|
||||
"@types/qrcode": "1.5.5",
|
||||
"better-auth": "1.2.4",
|
||||
"cookie-es": "2.0.0",
|
||||
"dayjs": "1.11.13",
|
||||
"dnum": "2.14.0",
|
||||
"es-toolkit": "1.32.0",
|
||||
"expo": "52.0.37",
|
||||
"es-toolkit": "1.33.0",
|
||||
"expo": "52.0.38",
|
||||
"expo-apple-authentication": "7.1.3",
|
||||
"expo-av": "15.0.2",
|
||||
"expo-blur": "14.0.3",
|
||||
"expo-build-properties": "0.13.2",
|
||||
"expo-clipboard": "7.0.1",
|
||||
"expo-constants": "17.0.7",
|
||||
"expo-constants": "17.0.8",
|
||||
"expo-dev-client": "5.0.12",
|
||||
"expo-document-picker": "13.0.3",
|
||||
"expo-file-system": "18.0.11",
|
||||
@@ -60,7 +62,7 @@
|
||||
"expo-linking": "7.0.5",
|
||||
"expo-localization": "16.0.1",
|
||||
"expo-media-library": "17.0.6",
|
||||
"expo-router": "4.0.17",
|
||||
"expo-router": "4.0.18",
|
||||
"expo-secure-store": "14.0.1",
|
||||
"expo-sharing": "13.0.1",
|
||||
"expo-splash-screen": "0.29.22",
|
||||
@@ -68,55 +70,56 @@
|
||||
"expo-status-bar": "2.0.1",
|
||||
"expo-symbols": "0.2.2",
|
||||
"expo-system-ui": "4.0.8",
|
||||
"expo-updates": "0.27.2",
|
||||
"expo-updates": "0.27.3",
|
||||
"expo-web-browser": "14.0.2",
|
||||
"hono": "4.7.2",
|
||||
"hono": "4.7.4",
|
||||
"immer": "10.1.1",
|
||||
"jotai": "2.12.1",
|
||||
"jotai": "2.12.2",
|
||||
"lru-cache": "11.0.2",
|
||||
"nanoid": "5.1.0",
|
||||
"nanoid": "5.1.3",
|
||||
"nativewind": "4.1.23",
|
||||
"ofetch": "1.4.1",
|
||||
"qrcode": "1.5.4",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-hook-form": "7.54.2",
|
||||
"react-native": "0.77.0",
|
||||
"react-native": "0.77.1",
|
||||
"react-native-awesome-slider": "2.9.0",
|
||||
"react-native-bouncy-checkbox": "4.1.2",
|
||||
"react-native-color-matrix-image-filters": "7.0.2",
|
||||
"react-native-device-info": "14.0.4",
|
||||
"react-native-gesture-handler": "2.24.0",
|
||||
"react-native-image-colors": "2.4.0",
|
||||
"react-native-ios-context-menu": "3.1.0",
|
||||
"react-native-ios-utilities": "5.1.1",
|
||||
"react-native-keyboard-controller": "1.16.3",
|
||||
"react-native-otp-entry": "1.8.2",
|
||||
"react-native-pager-view": "6.5.1",
|
||||
"react-native-reanimated": "3.16.7",
|
||||
"react-native-ios-utilities": "5.1.2",
|
||||
"react-native-keyboard-controller": "1.16.7",
|
||||
"react-native-otp-entry": "1.8.3",
|
||||
"react-native-pager-view": "6.7.0",
|
||||
"react-native-reanimated": "3.17.1",
|
||||
"react-native-root-siblings": "5.0.1",
|
||||
"react-native-safe-area-context": "5.3.0",
|
||||
"react-native-screens": "4.9.1",
|
||||
"react-native-screens": "4.9.2",
|
||||
"react-native-sheet-transitions": "0.1.2",
|
||||
"react-native-svg": "15.8.0",
|
||||
"react-native-svg": "15.11.2",
|
||||
"react-native-track-player": "4.1.1",
|
||||
"react-native-uikit-colors": "0.3.8",
|
||||
"react-native-video": "6.10.2",
|
||||
"react-native-volume-manager": "2.0.8",
|
||||
"react-native-web": "0.19.13",
|
||||
"react-native-webview": "13.12.5",
|
||||
"shiki": "3.0.0",
|
||||
"tailwindcss": "3.4.16",
|
||||
"react-native-webview": "13.13.4",
|
||||
"shiki": "3.2.1",
|
||||
"tailwindcss": "3.4.17",
|
||||
"usehooks-ts": "3.1.1",
|
||||
"zeego": "2.0.4",
|
||||
"zeego": "3.0.5",
|
||||
"zod": "3.24.2",
|
||||
"zustand": "5.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.26.9",
|
||||
"@babel/core": "7.26.10",
|
||||
"@types/react": "18.3.12",
|
||||
"babel-plugin-inline-import": "3.0.0",
|
||||
"babel-plugin-module-resolver": "5.0.2",
|
||||
"drizzle-kit": "0.30.4",
|
||||
"eas-cli": "15.0.10",
|
||||
"drizzle-kit": "0.30.5",
|
||||
"eas-cli": "15.0.15",
|
||||
"expo-drizzle-studio-plugin": "0.1.1",
|
||||
"postcss": "8.5.2"
|
||||
},
|
||||
@@ -124,10 +127,11 @@
|
||||
"expo": {
|
||||
"install": {
|
||||
"exclude": [
|
||||
"react-native",
|
||||
"react-native-gesture-handler",
|
||||
"react-native-screens",
|
||||
"react-native-safe-area-context"
|
||||
"react-native@~0.76.6",
|
||||
"react-native-gesture-handler@~2.20.0",
|
||||
"react-native-screens@~4.4.0",
|
||||
"react-native-safe-area-context@~4.12.0",
|
||||
"react-native-webview@~13.12.5"
|
||||
]
|
||||
},
|
||||
"autolinking": {
|
||||
|
||||
@@ -28,6 +28,9 @@ const createDefaultSettings = (): GeneralSettings => ({
|
||||
jumpOutLinkWarn: true,
|
||||
// TTS
|
||||
voice: "en-US-AndrewMultilingualNeural",
|
||||
|
||||
// Content
|
||||
openLinksInApp: true,
|
||||
})
|
||||
|
||||
export const {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Image as ExpoImage } from "expo-image"
|
||||
import { Animated, FlatList, Pressable, ScrollView, TouchableOpacity } from "react-native"
|
||||
import Reanimated from "react-native-reanimated"
|
||||
|
||||
import { Image } from "@/src/components/ui/image/Image"
|
||||
|
||||
export const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView)
|
||||
export const AnimatedFlatList = Animated.createAnimatedComponent(FlatList)
|
||||
export const AnimatedTouchableOpacity = Animated.createAnimatedComponent(TouchableOpacity)
|
||||
|
||||
export const ReAnimatedExpoImage = Reanimated.createAnimatedComponent(ExpoImage)
|
||||
export const ReAnimateImage = Reanimated.createAnimatedComponent(Image)
|
||||
export const ReAnimatedPressable = Reanimated.createAnimatedComponent(Pressable)
|
||||
export const ReAnimatedScrollView = Reanimated.createAnimatedComponent(ScrollView)
|
||||
export const ReAnimatedTouchableOpacity = Reanimated.createAnimatedComponent(TouchableOpacity)
|
||||
|
||||
@@ -9,7 +9,7 @@ export function NoLoginInfo({ target }: { target: "timeline" | "subscriptions" }
|
||||
return (
|
||||
<View className="flex-1 items-center justify-center gap-3">
|
||||
<Logo width={40} height={40} color={color} />
|
||||
<Text className="text-secondary-label text-xl">{`Sign in to Follow to see your ${target}.`}</Text>
|
||||
<Text className="text-secondary-label text-xl">{`Sign in to see your ${target}`}</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { cn } from "@follow/utils"
|
||||
import { getDefaultHeaderHeight, HeaderTitle } from "@react-navigation/elements"
|
||||
import { router, useNavigation } from "expo-router"
|
||||
import type { FC, PropsWithChildren, ReactNode } from "react"
|
||||
@@ -120,7 +121,7 @@ interface NavigationHeaderProps
|
||||
const blurThreshold = 0
|
||||
const titlebarPaddingHorizontal = 8
|
||||
const titleMarginHorizontal = 16
|
||||
export const NavigationHeader = ({
|
||||
export const InternalNavigationHeader = ({
|
||||
style,
|
||||
children,
|
||||
headerLeft,
|
||||
@@ -295,12 +296,21 @@ export const DefaultHeaderBackButton = ({ canGoBack }: { canGoBack: boolean }) =
|
||||
export const UINavigationHeaderActionButton = ({
|
||||
children,
|
||||
onPress,
|
||||
disabled,
|
||||
className,
|
||||
}: {
|
||||
children: ReactNode
|
||||
onPress?: () => void
|
||||
disabled?: boolean
|
||||
className?: string
|
||||
}) => {
|
||||
return (
|
||||
<TouchableOpacity hitSlop={5} className="p-2" onPress={onPress}>
|
||||
<TouchableOpacity
|
||||
hitSlop={5}
|
||||
className={cn("p-2", className)}
|
||||
onPress={onPress}
|
||||
disabled={disabled}
|
||||
>
|
||||
{children}
|
||||
</TouchableOpacity>
|
||||
)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { BottomTabBarProps } from "@react-navigation/bottom-tabs"
|
||||
import { Tabs } from "expo-router"
|
||||
import type { ForwardRefExoticComponent } from "react"
|
||||
import { forwardRef, useMemo, useRef, useState } from "react"
|
||||
import type { ScrollView } from "react-native"
|
||||
@@ -17,6 +16,7 @@ import {
|
||||
} from "./contexts/BottomTabBarVisibleContext"
|
||||
import { useNavigationScrollToTop } from "./hooks"
|
||||
import { Tabbar } from "./Tabbar"
|
||||
import { Tabs } from "./TabClient"
|
||||
|
||||
type ExtractReactForwardRefExoticComponent<T> =
|
||||
T extends React.ForwardRefExoticComponent<infer P> ? P : never
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user