File tree Expand file tree Collapse file tree 9 files changed +275
-0
lines changed Expand file tree Collapse file tree 9 files changed +275
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+ import { AccessibilityInfo } from 'react-native'
3
+
4
+ export default ( ) => {
5
+ const [ screenReaderEnabled , updateScreenReaderInfo ] = useState ( null )
6
+
7
+
8
+ useEffect ( ( ) => {
9
+ AccessibilityInfo . fetch ( ) . then ( ( isEnabled ) => {
10
+ updateScreenReaderInfo ( isEnabled )
11
+ } )
12
+ } , [ ] )
13
+
14
+ function onChange ( isEnabled ) {
15
+ updateScreenReaderInfo ( isEnabled )
16
+ }
17
+
18
+ useEffect ( ( ) => {
19
+ AccessibilityInfo . addEventListener ( 'change' , onChange )
20
+
21
+ return ( ) => AccessibilityInfo . removeEventListener ( 'change' , onChange )
22
+ } , [ ] )
23
+
24
+ return screenReaderEnabled
25
+ }
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+ import { AppState } from 'react-native'
3
+
4
+ const currentState = AppState . currentState
5
+
6
+ export default ( ) => {
7
+ const [ appState , setAppState ] = useState ( currentState )
8
+
9
+ function onChange ( newState ) {
10
+ setAppState ( newState )
11
+ }
12
+
13
+ useEffect ( ( ) => {
14
+ AppState . addEventListener ( 'change' , onChange )
15
+
16
+ return ( ) => {
17
+ AppState . removeEventListener ( 'change' , onChange )
18
+ }
19
+ } )
20
+
21
+ return appState
22
+ }
Original file line number Diff line number Diff line change
1
+ import React , { useState } from 'react'
2
+ import {
3
+ CameraRoll
4
+ } from 'react-native'
5
+
6
+ const initialState = {
7
+ edges : [ ] ,
8
+ page_info : {
9
+ end_cursor : '' ,
10
+ has_next_page : null ,
11
+ start_cursor : ''
12
+ }
13
+ }
14
+
15
+ const defaultConfig = {
16
+ first : 20 ,
17
+ groupTypes : 'All'
18
+ }
19
+
20
+ export default function ( ) {
21
+ const [ photos , setPhotos ] = useState ( initialState )
22
+
23
+ async function getPhotos ( config = defaultConfig ) {
24
+ try {
25
+ const photos = await CameraRoll . getPhotos ( config )
26
+ setPhotos ( photos )
27
+ } catch ( err ) {
28
+ console . log ( 'error: ' , err )
29
+ }
30
+ }
31
+
32
+ async function saveToCameraRoll ( tag , type ) {
33
+ try {
34
+ await CameraRoll . saveToCameraRoll ( tag , type )
35
+ } catch ( err ) {
36
+ console . log ( 'error saving to camera roll: ' , err )
37
+ }
38
+ }
39
+
40
+ return [ photos , getPhotos , saveToCameraRoll ]
41
+ }
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react' ;
2
+ import { Dimensions } from 'react-native' ;
3
+
4
+ const screen = Dimensions . get ( 'screen' ) ;
5
+
6
+ export default ( ) => {
7
+ const [ orientation , setOrientation ] = useState ( {
8
+ portrait : isOrientationPortrait ( screen ) ,
9
+ landscape : isOrientationLandscape ( screen )
10
+ } ) ;
11
+
12
+ isOrientationPortrait = ( { width, height } ) => height >= width ;
13
+ isOrientationLandscape = ( { width, height } ) => width >= height ;
14
+
15
+ onChange = ( { screen } ) => {
16
+ setOrientation ( {
17
+ portrait : isOrientationPortrait ( screen ) ,
18
+ landscape : isOrientationLandscape ( screen )
19
+ } ) ;
20
+ } ;
21
+
22
+ useEffect (
23
+ ( ) => {
24
+ Dimensions . addEventListener ( 'change' , onChange ) ;
25
+
26
+ return ( ) => {
27
+ Dimensions . removeEventListener ( 'change' , onChange ) ;
28
+ } ;
29
+ } ,
30
+ [ orientation . portrait , orientation . landscape ]
31
+ ) ;
32
+
33
+ return orientation ;
34
+ } ;
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+ import { Dimensions } from 'react-native'
3
+
4
+ const window = Dimensions . get ( 'window' )
5
+ const screen = Dimensions . get ( 'screen' )
6
+
7
+ export default ( ) => {
8
+ const [ dimensions , setDimensions ] = useState ( {
9
+ window, screen
10
+ } )
11
+
12
+ onChange = ( { window, screen } ) => {
13
+ setDimensions ( { window, screen } )
14
+ }
15
+
16
+ useEffect ( ( ) => {
17
+ Dimensions . addEventListener ( 'change' , onChange )
18
+
19
+ return ( ) => Dimensions . removeEventListener ( 'change' , onChange )
20
+ } , [ ] )
21
+
22
+ return dimensions
23
+ }
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+
3
+ const initialState = {
4
+ timeStamp : null ,
5
+ coords : {
6
+ accuracy : null ,
7
+ altitude : null ,
8
+ altitudeAccuracy : null ,
9
+ heading : null ,
10
+ latitude : null ,
11
+ longitude : null ,
12
+ speed : null
13
+ }
14
+ }
15
+
16
+ export default ( positionOptions = { } ) => {
17
+ const [ position , setPosition ] = useState ( initialState )
18
+
19
+ useEffect ( ( ) => {
20
+ navigator . geolocation . getCurrentPosition ( success , failure )
21
+ } , [ ] )
22
+
23
+ useEffect ( ( ) => {
24
+ const listener = navigator . geolocation . watchPosition (
25
+ success ,
26
+ failure ,
27
+ positionOptions
28
+ )
29
+
30
+ return ( ) => navigator . geolocation . clearWatch ( listener ) ;
31
+ } , [ ] )
32
+
33
+ function success ( data ) {
34
+ setPosition ( data )
35
+ }
36
+
37
+ function failure ( err ) {
38
+ console . log ( 'error setting coordinates: ' , err )
39
+ }
40
+
41
+ function setRNConfiguration ( config ) {
42
+ navigator . geolocation . setRNConfiguration ( config )
43
+ }
44
+
45
+ function stopObserving ( ) {
46
+ navigator . geolocation . stopObserving ( )
47
+ }
48
+
49
+ return [ position , stopObserving , setRNConfiguration ]
50
+ } ;
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react' ;
2
+ import { InteractionManager } from 'react-native' ;
3
+
4
+ export default ( ) => {
5
+ const [ complete , updateInteractionStatus ] = useState ( false ) ;
6
+
7
+ useEffect ( ( ) => {
8
+ InteractionManager . runAfterInteractions ( ( ) => {
9
+ updateInteractionStatus ( true )
10
+ } )
11
+ } , [ ] )
12
+ return complete
13
+ } ;
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+ import { Keyboard } from 'react-native'
3
+
4
+ export default ( ) => {
5
+ const [ keyboard , setKeyboard ] = useState ( { } )
6
+
7
+ keyboardWillShow = e => {
8
+ setKeyboard ( {
9
+ isKeyboardShow : true ,
10
+ keyboardHeight : e . endCoordinates . height
11
+ } )
12
+ }
13
+
14
+ keyboardWillHide = e => {
15
+ setKeyboard ( {
16
+ isKeyboardShow : false ,
17
+ keyboardHeight : e . endCoordinates . height
18
+ } )
19
+ }
20
+
21
+ useEffect ( ( ) => {
22
+ this . keyboardWillShowListener = Keyboard . addListener (
23
+ 'keyboardWillShow' ,
24
+ keyboardWillShow
25
+ )
26
+ this . keyboardWillHideListener = Keyboard . addListener (
27
+ 'keyboardWillHide' ,
28
+ keyboardWillHide
29
+ )
30
+
31
+ return ( ) => {
32
+ this . keyboardWillShowListener . remove ( )
33
+ this . keyboardWillHideListener . remove ( )
34
+ }
35
+ } , [ ] )
36
+ return keyboard
37
+ }
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+ import { NetInfo } from 'react-native'
3
+
4
+ const inititalState = {
5
+ type : null , effectiveType : null
6
+ }
7
+
8
+ export default ( ) => {
9
+ const [ netInfo , setNetInfo ] = useState ( inititalState )
10
+
11
+ onChange = ( newState ) => {
12
+ setNetInfo ( newState )
13
+ }
14
+
15
+ useEffect ( ( ) => {
16
+ NetInfo . getConnectionInfo ( ) . then ( ( connectionInfo ) => {
17
+ setNetInfo ( connectionInfo )
18
+ } )
19
+ } , [ ] )
20
+
21
+ useEffect ( ( ) => {
22
+ NetInfo . addEventListener ( 'connectionChange' , onChange )
23
+
24
+ return ( ) => {
25
+ NetInfo . removeEventListener ( 'connectionChange' , onChange )
26
+ }
27
+ } , [ ] )
28
+
29
+ return netInfo
30
+ }
You can’t perform that action at this time.
0 commit comments