diff --git a/apps/mobile/native/expo-module.config.json b/apps/mobile/native/expo-module.config.json index 6976c4ef1..937582675 100644 --- a/apps/mobile/native/expo-module.config.json +++ b/apps/mobile/native/expo-module.config.json @@ -1,7 +1,12 @@ { "platforms": ["apple", "android"], "apple": { - "modules": ["SharedWebViewModule", "HelperModule", "ToasterModule"] + "modules": [ + "SharedWebViewModule", + "HelperModule", + "ToasterModule", + "AppleIntelligenceGlowEffectModule" + ] }, "android": { "modules": [] diff --git a/apps/mobile/native/ios/AppleIntelligenceGlowEffect/AppleIntelligenceGlowEffect.swift b/apps/mobile/native/ios/AppleIntelligenceGlowEffect/AppleIntelligenceGlowEffect.swift new file mode 100644 index 000000000..bcd65779f --- /dev/null +++ b/apps/mobile/native/ios/AppleIntelligenceGlowEffect/AppleIntelligenceGlowEffect.swift @@ -0,0 +1,126 @@ +// AppleIntelligenceGlowEffect +// +// https://github.com/jacobamobin/AppleIntelligenceGlowEffect/blob/main/IOS.swift +// +import SwiftUI + +struct GlowEffect: View { + @State private var gradientStops: [Gradient.Stop] = GlowEffect.generateGradientStops() + + var body: some View { + ZStack { + EffectNoBlur(gradientStops: gradientStops, width: 6) + .onAppear { + // Start a timer to update the gradient stops every second + Timer.scheduledTimer(withTimeInterval: 0.4, repeats: true) { _ in + withAnimation(.easeInOut(duration: 0.5)) { + gradientStops = GlowEffect.generateGradientStops() + } + } + } + Effect(gradientStops: gradientStops, width: 9, blur: 4) + .onAppear { + // Start a timer to update the gradient stops every second + Timer.scheduledTimer(withTimeInterval: 0.4, repeats: true) { _ in + withAnimation(.easeInOut(duration: 0.6)) { + gradientStops = GlowEffect.generateGradientStops() + } + } + } + Effect(gradientStops: gradientStops, width: 11, blur: 12) + .onAppear { + // Start a timer to update the gradient stops every second + Timer.scheduledTimer(withTimeInterval: 0.4, repeats: true) { _ in + withAnimation(.easeInOut(duration: 0.8)) { + gradientStops = GlowEffect.generateGradientStops() + } + } + } + Effect(gradientStops: gradientStops, width: 15, blur: 15) + .onAppear { + // Start a timer to update the gradient stops every second + Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { _ in + withAnimation(.easeInOut(duration: 1)) { + gradientStops = GlowEffect.generateGradientStops() + } + } + } + } + } + + // Function to generate random gradient stops + static func generateGradientStops() -> [Gradient.Stop] { + [ + Gradient.Stop(color: Color(hex: "BC82F3"), location: Double.random(in: 0...1)), + Gradient.Stop(color: Color(hex: "F5B9EA"), location: Double.random(in: 0...1)), + Gradient.Stop(color: Color(hex: "8D9FFF"), location: Double.random(in: 0...1)), + Gradient.Stop(color: Color(hex: "FF6778"), location: Double.random(in: 0...1)), + Gradient.Stop(color: Color(hex: "FFBA71"), location: Double.random(in: 0...1)), + Gradient.Stop(color: Color(hex: "C686FF"), location: Double.random(in: 0...1)), + ].sorted { $0.location < $1.location } + } +} + +struct Effect: View { + var gradientStops: [Gradient.Stop] + var width: CGFloat + var blur: CGFloat + + var body: some View { + ZStack { + RoundedRectangle(cornerRadius: 55) + .strokeBorder( + AngularGradient( + gradient: Gradient(stops: gradientStops), + center: .center + ), + lineWidth: width + ) + .frame( + width: UIScreen.main.bounds.width, + height: UIScreen.main.bounds.height + ) + .padding(.top, -17) + .blur(radius: blur) + } + } +} + +struct EffectNoBlur: View { + var gradientStops: [Gradient.Stop] + var width: CGFloat + + var body: some View { + ZStack { + RoundedRectangle(cornerRadius: 55) + .strokeBorder( + AngularGradient( + gradient: Gradient(stops: gradientStops), + center: .center + ), + lineWidth: width + ) + .frame( + width: UIScreen.main.bounds.width, + height: UIScreen.main.bounds.height + ) + .padding(.top, -26) + } + } +} + +extension Color { + init(hex: String) { + let scanner = Scanner(string: hex) + _ = scanner.scanString("#") + + var hexNumber: UInt64 = 0 + scanner.scanHexInt64(&hexNumber) + + let r = Double((hexNumber & 0xff0000) >> 16) / 255 + let g = Double((hexNumber & 0x00ff00) >> 8) / 255 + let b = Double(hexNumber & 0x0000ff) / 255 + + self.init(red: r, green: g, blue: b) + } +} diff --git a/apps/mobile/native/ios/AppleIntelligenceGlowEffect/AppleIntelligenceGlowEffectModule.swift b/apps/mobile/native/ios/AppleIntelligenceGlowEffect/AppleIntelligenceGlowEffectModule.swift new file mode 100644 index 000000000..81f9d1ff8 --- /dev/null +++ b/apps/mobile/native/ios/AppleIntelligenceGlowEffect/AppleIntelligenceGlowEffectModule.swift @@ -0,0 +1,89 @@ +// +// AppleIntelligenceGlowEffectModule.swift +// Pods +// +// Created by Innei on 2025/2/24. +// + +import ExpoModulesCore +import SwiftUI +import UIKit + +public class AppleIntelligenceGlowEffectModule: Module { + private var hostingController: UIHostingController? + + public func definition() -> ModuleDefinition { + Name("AppleIntelligenceGlowEffect") + + Function("show") { + DispatchQueue.main.async { [weak self] in + guard let rootVC = Utils.getRootVC() else { return } + let hostingController = UIHostingController(rootView: GlowEffect()) + self?.hostingController = hostingController + + rootVC.addChild(hostingController) + rootVC.view.addSubview(hostingController.view) + hostingController.didMove(toParent: rootVC) + + hostingController.view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + hostingController.view.topAnchor.constraint(equalTo: rootVC.view.topAnchor), + hostingController.view.bottomAnchor.constraint(equalTo: rootVC.view.bottomAnchor), + hostingController.view.leadingAnchor.constraint(equalTo: rootVC.view.leadingAnchor), + hostingController.view.trailingAnchor.constraint(equalTo: rootVC.view.trailingAnchor), + ]) + + hostingController.view.backgroundColor = .clear + hostingController.view.isUserInteractionEnabled = false + + hostingController.view.transform = CGAffineTransform(scaleX: 1.1, y: 1.1) + UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut) { + hostingController.view.transform = .identity + } + } + } + + Function("hide") { + DispatchQueue.main.async { [weak self] in + guard let hostingController = self?.hostingController else { return } + + UIView.animate( + withDuration: 0.2, + animations: { + hostingController.view.alpha = 0 + hostingController.view.transform = CGAffineTransform(scaleX: 1.1, y: 1.1) + } + ) { _ in + hostingController.willMove(toParent: nil) + hostingController.view.removeFromSuperview() + hostingController.removeFromParent() + self?.hostingController = nil + } + } + } + } +} + +final class AppleIntelligenceGlowEffectView: UIViewControllerRepresentable { + func makeUIViewController(context: Context) -> UIViewController { + let viewController = UIViewController() + let hostingController = UIHostingController(rootView: GlowEffect()) + + viewController.addChild(hostingController) + viewController.view.addSubview(hostingController.view) + hostingController.didMove(toParent: viewController) + + hostingController.view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + hostingController.view.topAnchor.constraint(equalTo: viewController.view.topAnchor), + hostingController.view.bottomAnchor.constraint(equalTo: viewController.view.bottomAnchor), + hostingController.view.leadingAnchor.constraint(equalTo: viewController.view.leadingAnchor), + hostingController.view.trailingAnchor.constraint(equalTo: viewController.view.trailingAnchor), + ]) + + return viewController + } + func updateUIViewController(_ viewController: UIViewController, context: Context) { + + } +} diff --git a/apps/mobile/src/modules/debug/index.tsx b/apps/mobile/src/modules/debug/index.tsx index 948708d24..330582eea 100644 --- a/apps/mobile/src/modules/debug/index.tsx +++ b/apps/mobile/src/modules/debug/index.tsx @@ -4,14 +4,10 @@ import { atomWithStorage } from "jotai/utils" import { useMemo } from "react" import { Dimensions } from "react-native" import { Gesture, GestureDetector } from "react-native-gesture-handler" -import Animated, { - runOnJS, - useAnimatedStyle, - useSharedValue, - withSpring, -} from "react-native-reanimated" +import { runOnJS, useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated" import { useSafeAreaInsets } from "react-native-safe-area-context" +import { ReAnimatedTouchableOpacity } from "@/src/components/common/AnimatedComponents" import { BugCuteReIcon } from "@/src/icons/bug_cute_re" import { JotaiPersistSyncStorage } from "@/src/lib/jotai" @@ -67,7 +63,10 @@ export const DebugButton = () => { return ( - { + runOnJS(router.push)("/debug") + }} style={[ { position: "absolute", @@ -80,7 +79,7 @@ export const DebugButton = () => { className="absolute mt-5 flex size-8 items-center justify-center rounded-l-md bg-accent" > - + ) } diff --git a/apps/mobile/src/screens/(headless)/debug.tsx b/apps/mobile/src/screens/(headless)/debug.tsx index de1f373ff..765593650 100644 --- a/apps/mobile/src/screens/(headless)/debug.tsx +++ b/apps/mobile/src/screens/(headless)/debug.tsx @@ -1,4 +1,5 @@ import { sleep } from "@follow/utils" +import { requireNativeModule } from "expo" import * as Clipboard from "expo-clipboard" import * as FileSystem from "expo-file-system" import { Sitemap } from "expo-router/build/views/Sitemap" @@ -113,6 +114,19 @@ export default function DebugPanel() { ]) }, }, + + { + title: "Glow Effect", + onPress: () => { + requireNativeModule("AppleIntelligenceGlowEffect").show() + }, + }, + { + title: "Hide Glow Effect", + onPress: () => { + requireNativeModule("AppleIntelligenceGlowEffect").hide() + }, + }, ], },