Now displaying Notes correctly on the keys fixed map key issue and positionned correctly black keys using hard coded sizes

This commit is contained in:
Clément Le Bihan
2023-03-18 01:23:43 +01:00
parent cc364cfe7a
commit eb100e843b
+28 -11
View File
@@ -5,7 +5,7 @@ import {
octaveKeys, octaveKeys,
Accidental, Accidental,
} from "../../models/Piano"; } from "../../models/Piano";
import { Box, Row, Pressable, ZStack } from "native-base"; import { Box, Row, Pressable, ZStack, Text } from "native-base";
const notesList: Array<Note> = ["C", "D", "E", "F", "G", "A", "B"]; const notesList: Array<Note> = ["C", "D", "E", "F", "G", "A", "B"];
const accidentalsList: Array<Accidental> = ["#", "b", "##", "bb"]; const accidentalsList: Array<Accidental> = ["#", "b", "##", "bb"];
@@ -35,15 +35,20 @@ const Octave = ({
onNoteUp, onNoteUp,
}: OctaveProps) => { }: OctaveProps) => {
const oK: PianoKey[] = octaveKeys.map((k) => { const oK: PianoKey[] = octaveKeys.map((k) => {
return { ...k, number: number }; return new PianoKey(k.note, k.accidental, number);
}); });
const startNoteIndex = getKeyIndex(startNote, oK); const startNoteIndex = getKeyIndex(startNote, oK);
const endNoteIndex = getKeyIndex(endNote, oK); const endNoteIndex = getKeyIndex(endNote, oK);
const keys = oK.slice(startNoteIndex, endNoteIndex + 1); const keys = oK.slice(startNoteIndex, endNoteIndex + 1);
const whiteKeys = octaveKeys.filter((k) => k?.accidental === undefined); const whiteKeys = keys.filter((k) => k?.accidental === undefined);
const blackKeys = octaveKeys.filter((k) => k?.accidental !== undefined); const blackKeys = keys.filter((k) => k?.accidental !== undefined);
const whiteKeyWidthExpr = '50px';
const whiteKeyHeightExpr = '200px';
const blackKeyWidthExpr = '25px';
const blackKeyHeightExpr = '100px';
return ( return (
<Box width={"350px"} height={"200px"}> <Box width={"350px"} height={"200px"}>
@@ -52,18 +57,22 @@ const Octave = ({
{whiteKeys.map((key, i) => { {whiteKeys.map((key, i) => {
return ( return (
<Pressable <Pressable
key={i}
onPressIn={() => onNoteDown(key)} onPressIn={() => onNoteDown(key)}
onPressOut={() => onNoteUp(key)} onPressOut={() => onNoteUp(key)}
> >
<Box <Box
key={i}
bg="white" bg="white"
w="50px" w="50px"
h="200px" h="200px"
borderWidth="1px" borderWidth="1px"
borderColor="black" borderColor="black"
justifyContent="flex-end"
alignItems="center"
> >
{key.toString()} <Text fontSize="xl">
{key.note}
</Text>
</Box> </Box>
</Pressable> </Pressable>
); );
@@ -73,24 +82,32 @@ const Octave = ({
{blackKeys.map((key, i) => { {blackKeys.map((key, i) => {
return ( return (
<Pressable <Pressable
key={i}
onPressIn={() => onNoteDown(key)} onPressIn={() => onNoteDown(key)}
onPressOut={() => onNoteUp(key)} onPressOut={() => onNoteUp(key)}
> >
<Box <Box
key={i}
bg="black" bg="black"
w="25px" w="25px"
h="100px" h="120px"
borderWidth="1px" borderWidth="1px"
borderColor="black" borderColor="black"
marginLeft="12.5px" color="white"
style={{
position: "absolute",
left: `${(i + ((i > 1) as unknown as number)) * 50 + (50 - (25 / 2))}px`,
top: "0px",
justifyContent: "flex-end",
alignItems: "center",
}}
> >
{key.toString()} <Text fontSize="xs" color="white">
{key.note + key.accidental}
</Text>
</Box> </Box>
</Pressable> </Pressable>
); );
})} })}
;
</Row> </Row>
</ZStack> </ZStack>
</Box> </Box>