Compare commits
1
Commits
No files matched your search
@@ -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 (
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"platforms": ["apple"]
|
||||
}
|
||||
@@ -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 <UIKit/UIKit.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlagsOverridesOSSStable.h>
|
||||
|
||||
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<SwiftUIFilterFlags>());
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -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
|
||||
@@ -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])
|
||||
|
||||
Reference in new issue
Block a user