From effbf11f10ca67037f52898db103fec8e721dfbc Mon Sep 17 00:00:00 2001 From: Arthi-chaud Date: Thu, 5 Jan 2023 15:15:08 +0000 Subject: [PATCH] Front: Play Page: Request Midi Access --- front/Navigation.tsx | 4 ++-- front/views/PlayView.tsx | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/front/Navigation.tsx b/front/Navigation.tsx index 1f05ecf..f2faee1 100644 --- a/front/Navigation.tsx +++ b/front/Navigation.tsx @@ -11,17 +11,17 @@ import { useQuery } from 'react-query'; import API from './API'; import PlayView from './views/PlayView'; import ScoreView from './views/ScoreView'; -import { Center, Text } from 'native-base'; +import { Center } from 'native-base'; import LoadingComponent from './components/Loading'; import { RootState, useSelector } from './state/Store'; const Stack = createNativeStackNavigator(); export const protectedRoutes = <> + - ; diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index a7ef3fe..65220d8 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -1,24 +1,33 @@ import React, { Component } from 'react'; import { SafeAreaView, Text } from 'react-native'; import * as ScreenOrientation from 'expo-screen-orientation'; -import { Box, Center, Column, IconButton, Progress, Row, View } from 'native-base'; +import { Box, Center, Column, IconButton, Progress, Row, Toast, View } from 'native-base'; import { Ionicons } from "@expo/vector-icons"; import { useNavigation } from '@react-navigation/native'; +function onMIDISuccess(midiAccess) { + Toast.show({ description: `MIDI ready!` }); +} + +function onMIDIFailure(msg) { + Toast.show({ description: `Failed to get MIDI access - ${msg}` }); +} + class PlayView extends Component { override componentDidMount(): void { - ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE); + ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE).catch(() => {}); + navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure); } + override componentWillUnmount(): void { - ScreenOrientation.unlockAsync(); + ScreenOrientation.unlockAsync().catch(() => {}); } override render() { const score = 20; return ( -