diff --git a/apps/mobile/components/lyrics-view.tsx b/apps/mobile/components/lyrics-view.tsx index b55dd25..f73dce5 100644 --- a/apps/mobile/components/lyrics-view.tsx +++ b/apps/mobile/components/lyrics-view.tsx @@ -12,6 +12,7 @@ import Animated, { Easing, useAnimatedStyle, useSharedValue, + withSequence, withTiming, type SharedValue, } from "react-native-reanimated" @@ -284,13 +285,17 @@ function FilledWords({ useEffect(() => { cancelAnimation(sung) - sung.value = time - if (isPlaying && end > time) { - sung.value = withTiming(end, { - duration: (end - time) * 1000, - easing: Easing.linear, - }) - } + // Jump to the reported time first, so the wipe never runs from a stale one. + sung.value = + isPlaying && end > time + ? withSequence( + withTiming(time, { duration: 0 }), + withTiming(end, { + duration: (end - time) * 1000, + easing: Easing.linear, + }) + ) + : time }, [sung, time, isPlaying, end]) return ( diff --git a/apps/mobile/modules/swiftui-filters/expo-module.config.json b/apps/mobile/modules/swiftui-filters/expo-module.config.json new file mode 100644 index 0000000..876f466 --- /dev/null +++ b/apps/mobile/modules/swiftui-filters/expo-module.config.json @@ -0,0 +1,3 @@ +{ + "platforms": ["apple"] +} diff --git a/apps/mobile/modules/swiftui-filters/ios/SwiftUIFilters.mm b/apps/mobile/modules/swiftui-filters/ios/SwiftUIFilters.mm new file mode 100644 index 0000000..f0de7e9 --- /dev/null +++ b/apps/mobile/modules/swiftui-filters/ios/SwiftUIFilters.mm @@ -0,0 +1,37 @@ +// React Native draws `filter: [{ blur }]` on iOS only with its SwiftUI +// filters flag, which the stable release leaves off. This keeps the stable +// flags and turns that one on. + +#import +#import +#import + +using namespace facebook::react; + +class SwiftUIFilterFlags : public ReactNativeFeatureFlagsOverridesOSSStable { + public: + bool enableSwiftUIBasedFilters() override { + return true; + } +}; + +@interface SwiftUIFilters : NSObject +@end + +@implementation SwiftUIFilters + ++ (void)load +{ + // React Native sets its flags once while launching and throws if they were + // set first, so this waits for launch to finish. No views exist yet then. + [NSNotificationCenter.defaultCenter + addObserverForName:UIApplicationDidFinishLaunchingNotification + object:nil + queue:nil + usingBlock:^(NSNotification *notification) { + ReactNativeFeatureFlags::dangerouslyForceOverride( + std::make_unique()); + }]; +} + +@end diff --git a/apps/mobile/modules/swiftui-filters/ios/SwiftUIFilters.podspec b/apps/mobile/modules/swiftui-filters/ios/SwiftUIFilters.podspec new file mode 100644 index 0000000..7d4194e --- /dev/null +++ b/apps/mobile/modules/swiftui-filters/ios/SwiftUIFilters.podspec @@ -0,0 +1,14 @@ +Pod::Spec.new do |s| + s.name = 'SwiftUIFilters' + s.version = '1.0.0' + s.summary = 'Turns on React Native view filters like blur on iOS' + s.description = s.summary + s.license = { :type => 'MIT' } + s.author = 'oTunes' + s.homepage = 'https://otunes.abunchofknowitalls.com' + s.platforms = { :ios => '16.4' } + s.source = { :git => '' } + s.static_framework = true + install_modules_dependencies(s) + s.source_files = '**/*.{h,mm}' +end diff --git a/apps/web/components/lyrics-panel.tsx b/apps/web/components/lyrics-panel.tsx index 7d63333..6786f12 100644 --- a/apps/web/components/lyrics-panel.tsx +++ b/apps/web/components/lyrics-panel.tsx @@ -183,7 +183,8 @@ const SyncedLine = React.memo(function SyncedLine({ /** * The playing line's words, each filled as far as it has been sung. The - * browser runs the fills; playback updates only correct their drift. + * browser runs the fills on the song's timeline (a word's start is its + * delay); playback updates only correct their drift. */ function FilledWords({ words, @@ -200,6 +201,7 @@ function FilledWords({ React.useEffect(() => { fills.current = words.map((word, index) => spans.current[index]?.animate(WORD_FILL_FRAMES, { + delay: word.start * 1000, duration: Math.max(word.end - word.start, 0.05) * 1000, easing: "linear", fill: "both", @@ -209,15 +211,14 @@ function FilledWords({ }, [words]) React.useEffect(() => { + const at = time * 1000 fills.current.forEach((fill, index) => { if (!fill) return - const at = (time - words[index].start) * 1000 if (Math.abs(Number(fill.currentTime ?? 0) - at) > FILL_DRIFT_MS) { fill.currentTime = at } - // `play` on a finished fill would rewind it. - const duration = Number(fill.effect?.getTiming().duration ?? 0) - if (isPlaying && at < duration) fill.play() + // `play` on a finished fill would rewind it to the start. + if (isPlaying && time < words[index].end) fill.play() else fill.pause() }) }, [words, time, isPlaying])