File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import React from 'react'
33import { Image } from 'react-native'
44
5- // Mock font awesome
6- const Icon = 'Icon'
7- const getIconType = ( prefix ) => {
8- switch ( prefix ) {
9- case 'fas' :
10- return 'solid'
11- case 'fal' :
12- return 'light'
13- case 'fab' :
14- return 'brand'
15- default :
16- throw new Error ( )
5+ // === Globals ===
6+
7+ if ( typeof global . requestIdleCallback === 'undefined' ) {
8+ global . requestIdleCallback = function ( callback ) {
9+ return setTimeout ( function ( ) {
10+ callback ( {
11+ timeRemaining : function ( ) {
12+ return 50
13+ } ,
14+ didTimeout : false ,
15+ } )
16+ } , 0 )
1717 }
1818}
19- jest . mock ( '@fortawesome/react-native-fontawesome' , ( ) => ( {
20- FontAwesomeIcon : ( faIcon ) => (
21- < Icon
22- testID = { faIcon . testID }
23- color = { faIcon . color }
24- name = { faIcon . icon . iconName }
25- size = { faIcon . size }
26- style = { faIcon . style }
27- type = { getIconType ( faIcon . icon . prefix ) }
28- transform = { faIcon . transform }
29- />
30- ) ,
31- } ) )
19+
20+ if ( typeof global . cancelIdleCallback === 'undefined' ) {
21+ global . cancelIdleCallback = function ( id ) {
22+ clearTimeout ( id )
23+ }
24+ }
25+
26+ // === Third-party libraries ===
27+
28+ jest . mock ( '@fortawesome/react-native-fontawesome' , ( ) => {
29+ const Icon = 'Icon'
30+
31+ const getIconType = ( prefix ) => {
32+ switch ( prefix ) {
33+ case 'fas' :
34+ return 'solid'
35+ case 'fal' :
36+ return 'light'
37+ case 'fab' :
38+ return 'brand'
39+ default :
40+ throw new Error ( )
41+ }
42+ }
43+
44+ return {
45+ FontAwesomeIcon : ( faIcon ) => (
46+ < Icon
47+ testID = { faIcon . testID }
48+ color = { faIcon . color }
49+ name = { faIcon . icon . iconName }
50+ size = { faIcon . size }
51+ style = { faIcon . style }
52+ type = { getIconType ( faIcon . icon . prefix ) }
53+ transform = { faIcon . transform }
54+ />
55+ ) ,
56+ }
57+ } )
3258
3359Image . getSizeWithHeaders = jest . fn ( ( ) => Promise . resolve ( { width : 0 , height : 0 } ) )
Original file line number Diff line number Diff line change 11{
22 "name" : " @observation.org/react-native-components" ,
3- "version" : " 1.67 .0" ,
3+ "version" : " 1.68 .0" ,
44 "main" : " src/index.ts" ,
55 "repository" : " git@github.com:observation/react-native-components.git" ,
66 "author" : " Observation.org" ,
Original file line number Diff line number Diff line change 1+ declare global {
2+ function requestIdleCallback (
3+ callback : ( deadline : { timeRemaining ( ) : number ; didTimeout : boolean } ) => void ,
4+ options ?: { timeout : number } ,
5+ ) : number
6+
7+ function cancelIdleCallback ( handle : number ) : void
8+ }
9+
10+ export { }
Original file line number Diff line number Diff line change 11import React , { useState } from 'react'
2- import { InteractionManager , Platform } from 'react-native'
2+ import { Platform } from 'react-native'
33
44import { useFocusEffect } from '@react-navigation/native'
55
@@ -21,14 +21,14 @@ const useShowBlurView = () => {
2121 React . useCallback ( ( ) => {
2222 let timer : Timeout
2323 const timeout = isIOSDevice ? 0 : 200
24- const task = InteractionManager . runAfterInteractions ( ( ) => {
24+ const taskHandle = requestIdleCallback ( ( ) => {
2525 timer = setTimeout ( ( ) => {
2626 setShowBlurView ( true )
2727 } , timeout )
2828 } )
2929
3030 return ( ) => {
31- task . cancel ( )
31+ cancelIdleCallback ( taskHandle )
3232 clearTimeout ( timer )
3333 setShowBlurView ( isIOSDevice )
3434 }
Original file line number Diff line number Diff line change 11{
22 "extends" : " @react-native/typescript-config" ,
3+ "typeRoots" : [" ./src/@types" , " ./node_modules/@types" ],
34 "compilerOptions" : {
45 "types" : [" jest" ],
56 },
You can’t perform that action at this time.
0 commit comments