Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Adjusted release timings (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras authored May 26, 2022
1 parent 6a2fb6b commit 88d1fa0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/components/keyboard/Key.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Marker from "../Marker";
import Emoji from "../emojis/Emoji";
import React from "react";
import equal from "fast-deep-equal/react";
import { timing } from "../../constants";

export type PressedInfo = {
emojiId: string;
Expand Down Expand Up @@ -93,14 +94,14 @@ export default function Key({
opacityAnimation.stopAnimation();

if (pressed === undefined) {
const timing = ReactNative.Animated.timing(opacityAnimation, {
const animation = ReactNative.Animated.timing(opacityAnimation, {
toValue: 0.0,
duration: 100,
duration: timing.releaseAnimationDuration,
useNativeDriver: true,
});

timing.start();
return () => timing.stop();
animation.start();
return () => animation.stop();
} else {
opacityAnimation.setValue(1.0);
}
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Constants from "expo-constants";
import { Nunito_700Bold, Nunito_800ExtraBold } from "@expo-google-fonts/nunito";

export const timing = {
releaseAnimationDuration: 200,
decayDelay: 500,
decayDuration: 500,
};

export const codeLength = 3;

export const fonts = {
Expand Down
18 changes: 15 additions & 3 deletions src/sound/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as FileSystem from "expo-file-system";
import Sound from "./Sound";
import { getFullName } from "./utils";
import AsyncLock from "async-lock";
import { timing } from "../constants";

export default class Player {
private loaded: boolean = false;
Expand Down Expand Up @@ -96,8 +97,13 @@ export default class Player {
this.playingSounds.delete(note);
});

if (previousSound)
this._timeout(async () => await this._decaySound(previousSound, 100));
if (previousSound) {
const volume = (await previousSound.getVolume()) || 1.0;
this._timeout(
async () =>
await this._decaySound(previousSound, volume * timing.decayDelay)
);
}
}

async _stopSound(note: number, velocity: number) {
Expand All @@ -109,8 +115,14 @@ export default class Player {

this.playingSounds.delete(note);

const volume = (await sound.getVolume()) || 1.0;

this._timeout(
async () => await this._decaySound(sound, 100 + (1 - velocity) * 400)
async () =>
await this._decaySound(
sound,
volume * (timing.decayDelay + (1 - velocity) * timing.decayDuration)
)
);
}

Expand Down

0 comments on commit 88d1fa0

Please sign in to comment.