@@ -15,6 +15,7 @@ export default function App() {
1515 const [ isRecording , setIsRecording ] = useState ( false ) ;
1616 const [ recordedEvents , setRecordedEvents ] = useState < RecordedEvent [ ] > ( [ ] ) ;
1717 const [ hasRecording , setHasRecording ] = useState ( false ) ;
18+ const [ isPlayingPattern , setIsPlayingPattern ] = useState ( false ) ;
1819 const recordingStartTime = useRef < number | null > ( null ) ;
1920 const recordingTimeout = useRef < any > ( null ) ;
2021
@@ -130,45 +131,59 @@ export default function App() {
130131
131132 return (
132133 < View style = { styles . container } >
133- < TouchableOpacity
134- onPressIn = { ( ) => {
135- HapticPatterns . playHapticPattern ( maxPlayBackTime ) ;
136- if ( isRecording ) recordPress ( ) ;
137- } }
138- onPressOut = { ( ) => {
139- HapticPatterns . stopHapticPattern ( ) ;
140- if ( isRecording ) recordRelease ( ) ;
141- } }
142- style = { [ styles . button , isRecording && styles . recordingActive ] } >
143- < Text >
144- { Strings . pressToVibrate }
145- { isRecording ? ` (${ Strings . recording } )` : '' }
146- </ Text >
147- </ TouchableOpacity >
148-
149- < TouchableOpacity
150- onPress = { isRecording ? stopRecording : startRecording }
151- style = { [ styles . button , isRecording && styles . recordingButton ] } >
152- < Text >
153- { isRecording ? Strings . stopRecording : Strings . recordPattern }
154- </ Text >
155- </ TouchableOpacity >
156-
157- < TouchableOpacity
158- onPress = { ( ) => {
159- if ( recordedEvents . length ) {
160- HapticPatterns . playRecordedPattern ( recordedEvents ) ;
161- }
162- } }
163- style = { [ styles . button , ! hasRecording && styles . disabledButton ] }
164- disabled = { ! hasRecording } >
165- < Text > { Strings . playRecordedPattern } </ Text >
166- </ TouchableOpacity >
167-
168- { hasRecording && (
169- < TouchableOpacity onPress = { resetRecording } style = { styles . button } >
170- < Text > { Strings . resetRecording } </ Text >
171- </ TouchableOpacity >
134+ { isPlayingPattern ? (
135+ < View style = { styles . playingMessage } >
136+ < Text style = { styles . playingText } > Playing recorded pattern...</ Text >
137+ </ View >
138+ ) : (
139+ < >
140+ < TouchableOpacity
141+ onPressIn = { ( ) => {
142+ HapticPatterns . playHapticPattern ( maxPlayBackTime ) ;
143+ if ( isRecording ) recordPress ( ) ;
144+ } }
145+ onPressOut = { ( ) => {
146+ HapticPatterns . stopHapticPattern ( ) ;
147+ if ( isRecording ) recordRelease ( ) ;
148+ } }
149+ style = { [ styles . button , isRecording && styles . recordingActive ] } >
150+ < Text >
151+ { Strings . pressToVibrate }
152+ { isRecording ? ` (${ Strings . recording } )` : '' }
153+ </ Text >
154+ </ TouchableOpacity >
155+
156+ < TouchableOpacity
157+ onPress = { isRecording ? stopRecording : startRecording }
158+ style = { [ styles . button , isRecording && styles . recordingButton ] } >
159+ < Text >
160+ { isRecording ? Strings . stopRecording : Strings . recordPattern }
161+ </ Text >
162+ </ TouchableOpacity >
163+
164+ { hasRecording && (
165+ < TouchableOpacity
166+ onPress = { ( ) => {
167+ setIsPlayingPattern ( true ) ;
168+ HapticPatterns . playRecordedPattern ( recordedEvents ) . then ( ( ) => {
169+ setIsPlayingPattern ( false ) ;
170+ } ) ;
171+ } }
172+ style = { [ styles . button , isRecording && styles . disabledButton ] }
173+ disabled = { isRecording } >
174+ < Text > { Strings . playRecordedPattern } </ Text >
175+ </ TouchableOpacity >
176+ ) }
177+
178+ { hasRecording && (
179+ < TouchableOpacity
180+ onPress = { resetRecording }
181+ style = { [ styles . button , isRecording && styles . disabledButton ] }
182+ disabled = { isRecording } >
183+ < Text > { Strings . resetRecording } </ Text >
184+ </ TouchableOpacity >
185+ ) }
186+ </ >
172187 ) }
173188 </ View >
174189 ) ;
@@ -193,7 +208,7 @@ const styles = StyleSheet.create({
193208 } ,
194209 disabledButton : {
195210 backgroundColor : '#cccccc' ,
196- opacity : 0.7 ,
211+ opacity : 0.25 ,
197212 } ,
198213 box : {
199214 width : 60 ,
@@ -204,4 +219,15 @@ const styles = StyleSheet.create({
204219 borderWidth : 2 ,
205220 borderColor : '#ff6b6b' ,
206221 } ,
222+ playingMessage : {
223+ alignItems : 'center' ,
224+ justifyContent : 'center' ,
225+ padding : 20 ,
226+ } ,
227+ playingText : {
228+ fontSize : 18 ,
229+ fontWeight : 'bold' ,
230+ color : '#333' ,
231+ textAlign : 'center' ,
232+ } ,
207233} ) ;
0 commit comments