Commit 2 of 3:
df72682483
fix(haptics): keep the framework haptic helpers from failing on haptics left off
previous
next
whole branch
Review threads live on the whole diff, not on one commit, so
none are shown here - a thread's line means something in the
branch's final form, and painting it into an intermediate
step would put it on code it is not about.
docs/api/mobile/haptics.md modified +7 -0 Changes to docs/api/mobile/haptics.md ⋯ 1 line Show the 1 line above this hunk @@ -2,6 +2,13 @@2 2 3 3 Provide tactile feedback through device vibrations . 4 4 5 + Haptics are feedback , so these methods never stop a flow for a capability the 6 + app left off . On iOS , with `enableHaptics` off in `craft.config.json` , they 7 + resolve without playing anything , the way the web fallback does on a device 8 + with no vibration motor . They reject only when the native call itself fails . 9 + The raw `window.craft.haptic()` is different : it rejects with 10 + `CAPABILITY_DISABLED` , for code that needs to know . 11 + 5 12 ## Import 6 13 7 14 `` `typescript
packages/ios/README.md modified +11 -8 Changes to packages/ios/README.md ⋯ 158 lines Show the 158 lines above this hunk @@ -159,14 +159,17 @@ window.addEventListener('craftReady', (e) => { 159 159 console . log ( 'Capabilities:' , e . detail . capabilities ) ; 160 160 } ) ; 161 161 162 - / / Haptic feedback 163 - window . craft . haptic ( 'light' ) ; / / light , medium , heavy 164 - window . craft . haptic ( ' success ' ) ; / / success , warning , error 165 - window . craft . haptic ( ' selection ' ) ; 166 - 167 - / / Speech recognition 168 - window . craft . startListening ( ) ; 169 - window . craft . stopListening ( ) ; 162 + / / Haptic feedback . Resolves true , and rejects with CAPABILITY_DISABLED when 163 + / / enableHaptics is off . 164 + await window . craft . haptic ( ' light ' ) ; / / light , medium , heavy 165 + await window . craft . haptic ( ' success ' ) ; / / success , warning , error 166 + await window . craft . haptic ( 'selection' ) ; 167 + 168 + / / Speech recognition . startListening resolves true once the request is 169 + / / taken ; whether listening actually began arrives as the events below 170 + / / ( craftSpeechError for a declined prompt or no recognizer ) . 171 + await window . craft . startListening ( ) ; 172 + await window . craft . stopListening ( ) ; 170 173 171 174 / / Listen for speech events 172 175 window . addEventListener ( 'craftSpeechStart' , ( ) = > { / * recording started * / } ) ;
packages/react/src/index.ts modified +8 -1 Changes to packages/react/src/index.ts ⋯ 126 lines Show the 126 lines above this hunk @@ -127,7 +127,14 @@ export function useHaptic() { 127 127 console . warn ( 'Craft not ready' ) ; 128 128 return ; 129 129 } 130 - await craft . haptic ( type ) ; 130 + try { 131 + await craft . haptic ( type ) ; 132 + } 133 + catch ( error ) { 134 + 135 + 136 + if ( ( error as { code ? : string } | null ) ? . code !== 'CAPABILITY_DISABLED' ) throw error ; 137 + } 131 138 } , 132 139 [ craft , isReady ] 133 140 ) ;
packages/svelte/src/actions/haptic.ts modified +8 -1 Changes to packages/svelte/src/actions/haptic.ts ⋯ 4 lines Show the 4 lines above this hunk @@ -5,7 +5,14 @@ export function haptic(node: HTMLElement, type: string = 'selection') { 5 5 const handleClick = async ( ) => { 6 6 const _$craft = get ( craft ) ; 7 7 if ( ! _$craft ) return ; 8 - await _$craft . haptic ( type ) ; 8 + try { 9 + await _$craft . haptic ( type ) ; 10 + } 11 + catch ( error ) { 12 + 13 + 14 + if ( ( error as { code ? : string } | null ) ? . code !== 'CAPABILITY_DISABLED' ) throw error ; 15 + } 9 16 } ; 10 17 11 18 node . addEventListener ( 'click' , handleClick ) ;
packages/vue/src/index.ts modified +8 -1 Changes to packages/vue/src/index.ts ⋯ 127 lines Show the 127 lines above this hunk @@ -128,7 +128,14 @@ export function useHaptic() { 128 128 console . warn ( 'Craft not ready' ) ; 129 129 return ; 130 130 } 131 - await craft . value . haptic ( type ) ; 131 + try { 132 + await craft . value . haptic ( type ) ; 133 + } 134 + catch ( error ) { 135 + 136 + 137 + if ( ( error as { code ? : string } | null ) ? . code !== 'CAPABILITY_DISABLED' ) throw error ; 138 + } 132 139 } ; 133 140 134 141 return { haptic } ;