-
-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Adding `{ flex: 1 }` style is [described in the installation docs](https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation#js) but I _always_ forget to add it when creating a new app that uses gestures. I think others developers can relate. This PR adds a `{ flex: 1 }` fallback style to `GestureHandlerRootView` so users won't see a blank screen when they wrap their app with `GestureHandlerRootView`. ## Test plan Run an example app
- Loading branch information
1 parent
f58166c
commit 49379f3
Showing
4 changed files
with
34 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
import * as React from 'react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { ViewProps } from 'react-native'; | ||
import { ViewProps, StyleSheet } from 'react-native'; | ||
import { maybeInitializeFabric } from '../init'; | ||
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext'; | ||
import GestureHandlerRootViewNativeComponent from '../specs/RNGestureHandlerRootViewNativeComponent'; | ||
|
||
export interface GestureHandlerRootViewProps | ||
extends PropsWithChildren<ViewProps> {} | ||
|
||
export default function GestureHandlerRootView( | ||
props: GestureHandlerRootViewProps | ||
) { | ||
export default function GestureHandlerRootView({ | ||
style, | ||
...rest | ||
}: GestureHandlerRootViewProps) { | ||
// try initialize fabric on the first render, at this point we can | ||
// reliably check if fabric is enabled (the function contains a flag | ||
// to make sure it's called only once) | ||
maybeInitializeFabric(); | ||
|
||
return ( | ||
<GestureHandlerRootViewContext.Provider value> | ||
<GestureHandlerRootViewNativeComponent {...props} /> | ||
<GestureHandlerRootViewNativeComponent | ||
style={style ?? styles.container} | ||
{...rest} | ||
/> | ||
</GestureHandlerRootViewContext.Provider> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { flex: 1 }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,28 @@ | ||
import * as React from 'react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { View, ViewProps } from 'react-native'; | ||
import { View, ViewProps, StyleSheet } from 'react-native'; | ||
import { maybeInitializeFabric } from '../init'; | ||
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext'; | ||
|
||
export interface GestureHandlerRootViewProps | ||
extends PropsWithChildren<ViewProps> {} | ||
|
||
export default function GestureHandlerRootView( | ||
props: GestureHandlerRootViewProps | ||
) { | ||
export default function GestureHandlerRootView({ | ||
style, | ||
...rest | ||
}: GestureHandlerRootViewProps) { | ||
// try initialize fabric on the first render, at this point we can | ||
// reliably check if fabric is enabled (the function contains a flag | ||
// to make sure it's called only once) | ||
maybeInitializeFabric(); | ||
|
||
return ( | ||
<GestureHandlerRootViewContext.Provider value> | ||
<View {...props} /> | ||
<View style={style ?? styles.container} {...rest} /> | ||
</GestureHandlerRootViewContext.Provider> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { flex: 1 }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
import * as React from 'react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { View, ViewProps } from 'react-native'; | ||
import { View, ViewProps, StyleSheet } from 'react-native'; | ||
import GestureHandlerRootViewContext from '../GestureHandlerRootViewContext'; | ||
|
||
export interface GestureHandlerRootViewProps | ||
extends PropsWithChildren<ViewProps> {} | ||
|
||
export default function GestureHandlerRootView( | ||
props: GestureHandlerRootViewProps | ||
) { | ||
export default function GestureHandlerRootView({ | ||
style, | ||
...rest | ||
}: GestureHandlerRootViewProps) { | ||
return ( | ||
<GestureHandlerRootViewContext.Provider value> | ||
<View {...props} /> | ||
<View style={style ?? styles.container} {...rest} /> | ||
</GestureHandlerRootViewContext.Provider> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { flex: 1 }, | ||
}); |