-
-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #139 Removed RNGHModalUtils This class gave access to ReactModalHostView.DialogRootViewGroup in order to call #onChildStartedNativeGesture() and use instanceof on it. Checks for ReactRootView / DialogRootViewGroup can be unified by utilizing RootView (which both of those classes implement). Always render GestureHandlerRootView This prevents gestures from not being delivered to RNGH when another GestureHandlerRootView is used before modal (e.g. from React Navigation). Note: This isn't an ideal fix since a new orchestrator will be created, preventing modals from interacting with handlers outside of them. However, this use case is rare. Having gestures working in modals is already an improvement.
- Loading branch information
1 parent
d810dfa
commit 5572e8d
Showing
8 changed files
with
101 additions
and
67 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
android/src/main/java/com/facebook/react/views/modal/RNGHModalUtils.java
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as React from 'react'; | ||
import { useState } from 'react'; | ||
import { StyleSheet, Modal, View, Text } from 'react-native'; | ||
|
||
import { | ||
GestureHandlerRootView, | ||
TouchableOpacity, | ||
} from 'react-native-gesture-handler'; | ||
import { DraggableBox } from '../basic/draggable'; | ||
|
||
export default function App() { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
|
||
function ToggleModalButton() { | ||
return ( | ||
<TouchableOpacity | ||
style={styles.button} | ||
onPress={() => setIsModalVisible((visible) => !visible)}> | ||
<Text>{isModalVisible ? 'Close' : 'Open'} modal</Text> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
return ( | ||
<GestureHandlerRootView style={styles.container}> | ||
<Text style={styles.description}> | ||
DraggableBox inside modal should be moveable | ||
</Text> | ||
<ToggleModalButton /> | ||
<Modal visible={isModalVisible}> | ||
<GestureHandlerRootView style={{ flex: 1 }}> | ||
<View style={styles.modalView}> | ||
<DraggableBox /> | ||
<ToggleModalButton /> | ||
</View> | ||
</GestureHandlerRootView> | ||
</Modal> | ||
</GestureHandlerRootView> | ||
); | ||
} | ||
const styles = StyleSheet.create({ | ||
modalView: { | ||
margin: 20, | ||
marginTop: 200, | ||
backgroundColor: 'transparent', | ||
borderRadius: 6, | ||
padding: 20, | ||
alignItems: 'center', | ||
borderWidth: 2, | ||
}, | ||
container: { | ||
flex: 1, | ||
display: 'flex', | ||
alignItems: 'center', | ||
}, | ||
description: { | ||
margin: 20, | ||
}, | ||
button: { | ||
borderWidth: 2, | ||
padding: 10, | ||
}, | ||
}); |
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,34 +1,18 @@ | ||
import * as React from 'react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { View, requireNativeComponent } from 'react-native'; | ||
import { requireNativeComponent } from 'react-native'; | ||
import { GestureHandlerRootViewProps } from './GestureHandlerRootView'; | ||
|
||
const GestureHandlerRootViewNative = requireNativeComponent( | ||
'GestureHandlerRootView' | ||
); | ||
|
||
const GestureHandlerRootViewContext = React.createContext(false); | ||
|
||
type Props = PropsWithChildren<Record<string, unknown>>; | ||
|
||
export default function GestureHandlerRootView({ children, ...rest }: Props) { | ||
export default function GestureHandlerRootView({ | ||
children, | ||
...rest | ||
}: GestureHandlerRootViewProps) { | ||
return ( | ||
<GestureHandlerRootViewContext.Consumer> | ||
{(available) => { | ||
if (available) { | ||
// If we already have a parent wrapped in the gesture handler root view, | ||
// We don't need to wrap it again in root view | ||
// We still wrap it in a normal view so our styling stays the same | ||
return <View {...rest}>{children}</View>; | ||
} | ||
|
||
return ( | ||
<GestureHandlerRootViewContext.Provider value> | ||
<GestureHandlerRootViewNative {...rest}> | ||
{children} | ||
</GestureHandlerRootViewNative> | ||
</GestureHandlerRootViewContext.Provider> | ||
); | ||
}} | ||
</GestureHandlerRootViewContext.Consumer> | ||
<GestureHandlerRootViewNative {...rest}> | ||
{children} | ||
</GestureHandlerRootViewNative> | ||
); | ||
} |
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,3 +1,12 @@ | ||
import { View } from 'react-native'; | ||
import * as React from 'react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { View, ViewProps } from 'react-native'; | ||
|
||
export default View; | ||
export interface GestureHandlerRootViewProps | ||
extends PropsWithChildren<ViewProps> {} | ||
|
||
export default function GestureHandlerRootView({ | ||
...rest | ||
}: GestureHandlerRootViewProps) { | ||
return <View {...rest} />; | ||
} |
5572e8d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this!