From 5ac87cc877b8dafd1a7dd5628d1eed095ddbe072 Mon Sep 17 00:00:00 2001 From: Hubert Gancarczyk Date: Tue, 16 Jul 2024 15:38:41 +0200 Subject: [PATCH] style: move installation process, fix indents --- example/src/App.tsx | 54 +++++++++++++++--------------------- ios/AudioContextModule.mm | 20 +++++++------ ios/PlatformOscillator.mm | 24 ++++++++-------- src/AudioContext.ts | 6 +--- src/Oscillator/Oscillator.ts | 37 ------------------------ src/Oscillator/index.ts | 1 + src/Oscillator/types.ts | 6 ---- src/index.ts | 6 +++- src/modules/global.d.ts | 8 ++++++ src/utils/install.ts | 34 +++++++++++++++++------ 10 files changed, 86 insertions(+), 110 deletions(-) delete mode 100644 src/Oscillator/Oscillator.ts create mode 100644 src/Oscillator/index.ts create mode 100644 src/modules/global.d.ts diff --git a/example/src/App.tsx b/example/src/App.tsx index fb5f2389..7149d672 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,56 +1,46 @@ -import React, { useCallback, useRef, useState } from 'react'; -import { StyleSheet, View, Button, TextInput } from 'react-native'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; +import { StyleSheet, View, Button, TextInput, Text } from 'react-native'; import { AudioContext, type OscillatorNode } from 'react-native-audio-context'; +const BASE_FREQUENCY = 440; + const App: React.FC = () => { - const [frequency, setFrequency] = useState('440'); + const [frequency, setFrequency] = useState(BASE_FREQUENCY); const osc = useRef(null); + const osc2 = useRef(null); - const start = useCallback(() => { + useEffect(() => { if (!osc.current) { const context = new AudioContext(); osc.current = context.createOscillator(+frequency); + osc2.current = context.createOscillator(+frequency); } - - osc.current.start(); - }, [frequency]); - - const stop = useCallback(() => { - if (!osc.current) { - return; - } - - osc.current.stop(); + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - const changeFrequency = useCallback(() => { - if (!osc.current) { - return; + useEffect(() => { + if (osc.current) { + osc.current.frequency = frequency; } - - osc.current.frequency = parseFloat(frequency); }, [frequency]); - const getFrequency = useCallback(() => { - if (!osc.current) { - return; - } - - console.log(osc.current.frequency); + const start = useCallback(() => { + osc.current?.start(); + }, []); - return osc.current.frequency; + const stop = useCallback(() => { + osc.current?.stop(); }, []); return ( -