-
-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: clicking on Pressable located in screen header #2466
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
0044582
remove header offset from RNSScreenStackHeaderConfigShadowNode
coado fa6ba8c
remove top: '-100%' from ScreenStackHeaderConfig
coado 47212d4
rename topInsetOffset to paddingTop in RNSScreenStackHeaderConfigShad…
coado 7aa8889
Merge branch 'main' into @dmalecki/pressable-in-header
coado 0d80a85
header config frame
coado 8047046
header config state
coado 76681bb
header subview frame size update
coado 92b899a
header subview frame corrections
coado cfb237e
remove unused import
coado 83fb6f4
flattened header subviews
coado 5d6716d
iOS frame metrics
coado b3ebaf5
flattening
coado b9e0124
fix Android
coado aad021a
fix layout iOS subviews
coado 43ddcb2
header config and subviews position
coado eca6580
fix not completed layout
coado 0823b03
fix subview hit test bug
coado 61f2f9d
hit testing flattened views on iOS
coado 3b5ee9d
sending subviews frames on fabric
coado f07b8de
merge
coado d6e1597
fix Android build paper
coado 723e8a9
FabricEnabledHeaderSubviewGroup empty line
coado b71e62e
remove RNSScreenStackHeaderConfigShadowNode include
coado 8541afc
remove unused origin from header config state
coado 396abd4
caching header config size, iOS
coado 9799d47
_lastSize recycle
coado f7bfbd7
remove sending top inset, paper
coado c71ce45
fix Android build
coado 3337de6
Add reproduction
kkafar 86e64c2
Merge branch 'main' into @dmalecki/pressable-in-header
kkafar ae32702
Merge branch 'main' into @dmalecki/pressable-in-header
kkafar b7afeb9
Update TestHeaderTitle & Test2466 examples
kkafar c29cf9b
Fix regression on header layout with long / short titles
kkafar d4835ec
Cpp formatter
kkafar d6a7b4d
Fix updateHeaderConfigState method signature on Paper
kkafar 65b8699
Cleanup example a bit
kkafar 0f8323a
Cleanup Android code a bit
kkafar ea74898
Make some parts of cpp code Android-only
kkafar 40f550c
Make `applyFrameCorrections` method private
kkafar 8f8eaae
Cosmetic changes in iOS code
kkafar 840c3d9
Remove contentOffset from header config
kkafar 2703a0f
Default initialize contentOffset in SubviewState
kkafar f6f78c2
A bit more of cleanup & refactor of iOS code
kkafar 45e0cca
Remove contentOffset from header config on Android side
kkafar f859ccb
Example improvements
kkafar d62fe03
Handle cases when subview is added after initial render
kkafar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
51 changes: 51 additions & 0 deletions
51
android/src/fabric/java/com/swmansion/rnscreens/FabricEnabledHeaderSubviewGroup.kt
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,51 @@ | ||
package com.swmansion.rnscreens | ||
|
||
import android.content.Context | ||
import android.view.ViewGroup | ||
import androidx.annotation.UiThread | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.bridge.WritableNativeMap | ||
import com.facebook.react.uimanager.PixelUtil | ||
import com.facebook.react.uimanager.StateWrapper | ||
|
||
abstract class FabricEnabledHeaderSubviewGroup( | ||
context: Context?, | ||
) : ViewGroup(context) { | ||
private var mStateWrapper: StateWrapper? = null | ||
|
||
fun setStateWrapper(wrapper: StateWrapper?) { | ||
mStateWrapper = wrapper | ||
} | ||
|
||
protected fun updateSubviewFrameState( | ||
width: Int, | ||
height: Int, | ||
offsetX: Int, | ||
offsetY: Int, | ||
) { | ||
updateState(width, height, offsetX, offsetY) | ||
} | ||
|
||
@UiThread | ||
fun updateState( | ||
width: Int, | ||
height: Int, | ||
offsetX: Int, | ||
offsetY: Int, | ||
) { | ||
val realWidth: Float = PixelUtil.toDIPFromPixel(width.toFloat()) | ||
val realHeight: Float = PixelUtil.toDIPFromPixel(height.toFloat()) | ||
val offsetXDip: Float = PixelUtil.toDIPFromPixel(offsetX.toFloat()) | ||
val offsetYDip: Float = PixelUtil.toDIPFromPixel(offsetY.toFloat()) | ||
|
||
val map: WritableMap = | ||
WritableNativeMap().apply { | ||
putDouble("frameWidth", realWidth.toDouble()) | ||
putDouble("frameHeight", realHeight.toDouble()) | ||
putDouble("contentOffsetX", offsetXDip.toDouble()) | ||
putDouble("contentOffsetY", offsetYDip.toDouble()) | ||
} | ||
|
||
mStateWrapper?.updateState(map) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ import com.facebook.react.views.view.ReactViewGroup | |
@SuppressLint("ViewConstructor") | ||
class ScreenStackHeaderSubview( | ||
context: ReactContext?, | ||
) : ReactViewGroup(context) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You made |
||
) : FabricEnabledHeaderSubviewGroup(context) { | ||
private var reactWidth = 0 | ||
private var reactHeight = 0 | ||
var type = Type.RIGHT | ||
|
@@ -37,11 +37,17 @@ class ScreenStackHeaderSubview( | |
|
||
override fun onLayout( | ||
changed: Boolean, | ||
left: Int, | ||
top: Int, | ||
right: Int, | ||
bottom: Int, | ||
) = Unit | ||
l: Int, | ||
t: Int, | ||
r: Int, | ||
b: Int, | ||
) { | ||
if (changed && BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { | ||
val width = r - l; | ||
val height = b - t; | ||
updateSubviewFrameState(width, height, l, t) | ||
} | ||
} | ||
|
||
enum class Type { | ||
LEFT, | ||
|
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
18 changes: 18 additions & 0 deletions
18
android/src/paper/java/com/swmansion/rnscreens/FabricEnabledHeaderSubviewGroup.kt
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,18 @@ | ||
package com.swmansion.rnscreens | ||
|
||
import android.content.Context | ||
import android.view.ViewGroup | ||
import com.facebook.react.uimanager.StateWrapper | ||
|
||
abstract class FabricEnabledHeaderSubviewGroup(context: Context?): ViewGroup(context) { | ||
|
||
fun setStateWrapper(wrapper: StateWrapper?) = Unit | ||
|
||
// Fabric only | ||
protected fun updateSubviewFrameState( | ||
width: Int, | ||
height: Int, | ||
offsetX: Int, | ||
offsetY: Int | ||
) = Unit | ||
} |
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,155 @@ | ||
import { Header } from '@react-navigation/elements'; | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { createNativeStackNavigator, NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
import React, { ForwardedRef } from 'react'; | ||
import { findNodeHandle, GestureResponderEvent, Pressable, PressableProps, StyleSheet, Text, View } from 'react-native'; | ||
|
||
type StackParamList = { | ||
Home: undefined, | ||
} | ||
|
||
type RouteProps = { | ||
navigation: NativeStackNavigationProp<StackParamList>; | ||
} | ||
|
||
type PressableState = 'pressed-in' | 'pressed' | 'pressed-out' | ||
|
||
|
||
const Stack = createNativeStackNavigator<StackParamList>(); | ||
|
||
const PressableWithFeedback = React.forwardRef((props: PressableProps, ref: ForwardedRef<View>): React.JSX.Element => { | ||
const [pressedState, setPressedState] = React.useState<PressableState>('pressed-out'); | ||
|
||
const onPressInCallback = React.useCallback((e: GestureResponderEvent) => { | ||
console.log('Pressable onPressIn', { | ||
locationX: e.nativeEvent.locationX, | ||
locationY: e.nativeEvent.locationY, | ||
pageX: e.nativeEvent.pageX, | ||
pageY: e.nativeEvent.pageY, | ||
}); | ||
setPressedState('pressed-in'); | ||
props.onPressIn?.(e); | ||
}, [props]); | ||
|
||
const onPressCallback = React.useCallback((e: GestureResponderEvent) => { | ||
console.log('Pressable onPress'); | ||
setPressedState('pressed'); | ||
props.onPress?.(e); | ||
}, [props]); | ||
|
||
const onPressOutCallback = React.useCallback((e: GestureResponderEvent) => { | ||
console.log('Pressable onPressOut'); | ||
setPressedState('pressed-out'); | ||
props.onPressOut?.(e); | ||
}, [props]); | ||
|
||
const onResponderMoveCallback = React.useCallback((e: GestureResponderEvent) => { | ||
console.log('Pressable onResponderMove'); | ||
props.onResponderMove?.(e); | ||
}, [props]); | ||
|
||
const contentsStyle = pressedState === 'pressed-out' | ||
? styles.pressablePressedOut | ||
: (pressedState === 'pressed' | ||
? styles.pressablePressed | ||
: styles.pressablePressedIn); | ||
|
||
return ( | ||
<View ref={ref} style={[contentsStyle]}> | ||
<Pressable | ||
onPressIn={onPressInCallback} | ||
onPress={onPressCallback} | ||
onPressOut={onPressOutCallback} | ||
onResponderMove={onResponderMoveCallback} | ||
> | ||
{props.children} | ||
</Pressable> | ||
</View> | ||
|
||
); | ||
}); | ||
|
||
function HeaderTitle(): React.JSX.Element { | ||
return ( | ||
<PressableWithFeedback | ||
onLayout={event => { | ||
const { x, y, width, height } = event.nativeEvent.layout; | ||
console.log('Title onLayout', { x, y, width, height }); | ||
}} | ||
onPressIn={() => { | ||
console.log('Pressable onPressIn'); | ||
}} | ||
onPress={() => console.log('Pressable onPress')} | ||
onPressOut={() => console.log('Pressable onPressOut')} | ||
onResponderMove={() => console.log('Pressable onResponderMove')} | ||
ref={node => { | ||
console.log(findNodeHandle(node)); | ||
node?.measure((x, y, width, height, pageX, pageY) => { | ||
console.log('header component measure', { x, y, width, height, pageX, pageY }); | ||
}); | ||
}} | ||
> | ||
<View style={{ height: 40, justifyContent: 'center', alignItems: 'center' }}> | ||
<Text style={{ alignItems: 'center' }}>Regular Pressable</Text> | ||
</View> | ||
</PressableWithFeedback> | ||
); | ||
} | ||
|
||
function HeaderLeft(): React.JSX.Element { | ||
return ( | ||
<HeaderTitle /> | ||
); | ||
} | ||
|
||
function Home(_: RouteProps): React.JSX.Element { | ||
return ( | ||
<View style={{ flex: 1, backgroundColor: 'rgba(0, 0, 0, .8)' }} | ||
> | ||
<View style={{ flex: 1, alignItems: 'center', marginTop: 48 }}> | ||
<PressableWithFeedback | ||
onPressIn={() => console.log('Pressable onPressIn')} | ||
onPress={() => console.log('Pressable onPress')} | ||
onPressOut={() => console.log('Pressable onPressOut')} | ||
> | ||
<View style={{ height: 40, width: 200, justifyContent: 'center', alignItems: 'center' }}> | ||
<Text style={{ alignItems: 'center' }}>Regular Pressable</Text> | ||
</View> | ||
</PressableWithFeedback> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
function App(): React.JSX.Element { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="Home" | ||
component={Home} | ||
options={{ | ||
headerTitle: HeaderTitle, | ||
headerLeft: HeaderLeft, | ||
headerRight: HeaderLeft, | ||
}} | ||
/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
pressablePressedIn: { | ||
backgroundColor: 'lightsalmon', | ||
}, | ||
pressablePressed: { | ||
backgroundColor: 'crimson', | ||
}, | ||
pressablePressedOut: { | ||
backgroundColor: 'lightseagreen', | ||
}, | ||
}); | ||
|
||
|
||
export default App; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Padding must be sent here, well... to account for native padding of support library toolbar. Otherwise we introduce regressions, see the PR that introduced
TestHeaderTitle
.