-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
97 lines (87 loc) · 2.89 KB
/
App.js
File metadata and controls
97 lines (87 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/** React */
import React, { Component } from "react";
import { PermissionsAndroid } from "react-native";
/** Async Storage */
import AsyncStorage from "@react-native-async-storage/async-storage";
/** Redux */
import redux, { applyMiddleware, createStore } from "redux";
import { Provider } from "react-redux";
import { persistStore, persistReducer } from "redux-persist";
import { PersistGate } from "redux-persist/integration/react";
/** Reducers */
import noteReducer from "./src/reducers/noteReducer";
/** Navigation */
import { NavigationContainer } from "@react-navigation/native";
/** React Native Screens */
import { enableScreens } from "react-native-screens";
/** Tabs */
import Tabs from "./screens/tabs";
/** Tuner class */
import Tuner from "./src/tuner";
import beatsCalc from "./src/beats";
import inharmonicityCalc from "./src/inharmonicity";
/** --------------- FINE IMPORTS ---------------- */
enableScreens(true);
/** Redux Persist */
const persistConfig = {
key: "root",
storage: AsyncStorage,
whitelist: ["inharmonicity"],
};
const persistedReducer = persistReducer(persistConfig, noteReducer);
/** Creazione dello stato dell'app. */
const store = createStore(persistedReducer);
//const store = createStore(noteReducer);
const persistedStore = persistStore(store);
/** Creiamo l'oggetto Tuner */
//persistedStore.purge();
const tuner = new Tuner(store.getState().middleA);
export default class App extends Component {
constructor(props) {
super(props);
}
/** Quando il componente viene montato */
async componentDidMount() {
/* Android permissions request */
if (Platform.OS === "android") {
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
]);
}
/** Il Tuner parte in modalita' OFF */
store.dispatch({ type: "switchOff" });
/** Dispatching actions to update state */
tuner.onNoteDetected = (note) => {
if (this._lastNoteName === note.name) {
store.dispatch({ type: "changeNote", value: note });
} else {
this._lastNoteName = note.name;
}
};
}
handleSwitchTuner = () => {
store.dispatch({ type: "SWITCH" });
if (store.getState().tunerSwitch) tuner.start();
else tuner.stop();
};
handleInharmonicitySave = (_inharmonicity) => {
store.dispatch({ type: "changeInharmonicity", value: _inharmonicity });
};
/** Il provider contiene lo store e i componenti figli possono vederlo. */
render() {
return (
<NavigationContainer>
<Provider store={store}>
<PersistGate loading={null} persistor={persistedStore}>
<Tabs
handleSwitch={this.handleSwitchTuner}
beatsCalc={beatsCalc}
inharmonicityCalc={inharmonicityCalc}
inharmonicitySave={this.handleInharmonicitySave}
/>
</PersistGate>
</Provider>
</NavigationContainer>
);
}
}