feat(mobile): add Apple Intelligence glow effect module for iOS

- Implement AppleIntelligenceGlowEffectModule with show/hide functionality
- Create SwiftUI-based glow effect with dynamic gradient animations
- Update expo-module.config.json to include new native module
- Add debug panel options to trigger glow effect
- Enhance DebugButton with ReAnimatedTouchableOpacity

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-02-24 23:51:54 +08:00
parent 09ccd39496
commit e75c37fa80
5 changed files with 242 additions and 9 deletions
+6 -1
View File
@@ -1,7 +1,12 @@
{
"platforms": ["apple", "android"],
"apple": {
"modules": ["SharedWebViewModule", "HelperModule", "ToasterModule"]
"modules": [
"SharedWebViewModule",
"HelperModule",
"ToasterModule",
"AppleIntelligenceGlowEffectModule"
]
},
"android": {
"modules": []
@@ -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)
}
}
@@ -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<GlowEffect>?
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) {
}
}
+7 -8
View File
@@ -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 (
<GestureDetector gesture={gestureEvent}>
<Animated.View
<ReAnimatedTouchableOpacity
onPress={() => {
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"
>
<BugCuteReIcon height={24} width={24} color="#fff" />
</Animated.View>
</ReAnimatedTouchableOpacity>
</GestureDetector>
)
}
@@ -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()
},
},
],
},