-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31055 from margelo/origin/feat/update-loading-scr…
…een-to-play-animation-and-sound feat: app sounds
- Loading branch information
Showing
29 changed files
with
318 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
diff --git a/node_modules/react-native-sound/RNSound/RNSound.h b/node_modules/react-native-sound/RNSound/RNSound.h | ||
index 7f5b97b..1a3c840 100644 | ||
--- a/node_modules/react-native-sound/RNSound/RNSound.h | ||
+++ b/node_modules/react-native-sound/RNSound/RNSound.h | ||
@@ -1,17 +1,7 @@ | ||
-#if __has_include(<React/RCTBridgeModule.h>) | ||
#import <React/RCTBridgeModule.h> | ||
-#else | ||
-#import "RCTBridgeModule.h" | ||
-#endif | ||
- | ||
#import <AVFoundation/AVFoundation.h> | ||
- | ||
-#if __has_include(<React/RCTEventEmitter.h>) | ||
#import <React/RCTEventEmitter.h> | ||
-#else | ||
-#import "RCTEventEmitter.h" | ||
-#endif | ||
|
||
@interface RNSound : RCTEventEmitter <RCTBridgeModule, AVAudioPlayerDelegate> | ||
-@property (nonatomic, weak) NSNumber *_key; | ||
+@property(nonatomic, weak) NSNumber *_key; | ||
@end | ||
diff --git a/node_modules/react-native-sound/RNSound/RNSound.m b/node_modules/react-native-sound/RNSound/RNSound.m | ||
index df3784e..d34ac01 100644 | ||
--- a/node_modules/react-native-sound/RNSound/RNSound.m | ||
+++ b/node_modules/react-native-sound/RNSound/RNSound.m | ||
@@ -1,10 +1,6 @@ | ||
#import "RNSound.h" | ||
|
||
-#if __has_include("RCTUtils.h") | ||
-#import "RCTUtils.h" | ||
-#else | ||
#import <React/RCTUtils.h> | ||
-#endif | ||
|
||
@implementation RNSound { | ||
NSMutableDictionary *_playerPool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const config = {prefix: ''}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const config = {prefix: '/sounds/'}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import Sound from 'react-native-sound'; | ||
import type {ValueOf} from 'type-fest'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import config from './config'; | ||
|
||
let isMuted = false; | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.USER, | ||
callback: (val) => (isMuted = !!val?.isMutedAllSounds), | ||
}); | ||
|
||
const SOUNDS = { | ||
DONE: 'done', | ||
SUCCESS: 'success', | ||
ATTENTION: 'attention', | ||
RECEIVE: 'receive', | ||
} as const; | ||
|
||
/** | ||
* Creates a version of the given function that, when called, queues the execution and ensures that | ||
* calls are spaced out by at least the specified `minExecutionTime`, even if called more frequently. This allows | ||
* for throttling frequent calls to a function, ensuring each is executed with a minimum `minExecutionTime` between calls. | ||
* Each call returns a promise that resolves when the function call is executed, allowing for asynchronous handling. | ||
*/ | ||
function withMinimalExecutionTime<F extends (...args: Parameters<F>) => ReturnType<F>>(func: F, minExecutionTime: number) { | ||
const queue: Array<[() => ReturnType<F>, (value?: unknown) => void]> = []; | ||
let timerId: NodeJS.Timeout | null = null; | ||
|
||
function processQueue() { | ||
if (queue.length > 0) { | ||
const next = queue.shift(); | ||
|
||
if (!next) { | ||
return; | ||
} | ||
|
||
const [nextFunc, resolve] = next; | ||
nextFunc(); | ||
resolve(); | ||
timerId = setTimeout(processQueue, minExecutionTime); | ||
} else { | ||
timerId = null; | ||
} | ||
} | ||
|
||
return function (...args: Parameters<F>) { | ||
return new Promise((resolve) => { | ||
queue.push([() => func(...args), resolve]); | ||
|
||
if (!timerId) { | ||
// If the timer isn't running, start processing the queue | ||
processQueue(); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
const playSound = (soundFile: ValueOf<typeof SOUNDS>) => { | ||
const sound = new Sound(`${config.prefix}${soundFile}.mp3`, Sound.MAIN_BUNDLE, (error) => { | ||
if (error || isMuted) { | ||
return; | ||
} | ||
|
||
sound.play(); | ||
}); | ||
}; | ||
|
||
export {SOUNDS}; | ||
export default withMinimalExecutionTime(playSound, 300); |
Oops, something went wrong.