-
-
Notifications
You must be signed in to change notification settings - Fork 546
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(iOS): header left and right layout on fabric #2248
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ebe3d7
Added repro
alduzy 514b8da
Subview layout fix
alduzy c592724
Merge remote-tracking branch 'origin/main' into @alduzy/fabric-header…
alduzy 089fc0b
simplified test
alduzy 74937b6
removed import
alduzy 436409f
Added comment
alduzy 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
import React, { useLayoutEffect, useState } from 'react'; | ||
import { View } from 'react-native'; | ||
|
||
import { SettingsSwitch, Square } from '../shared'; | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
|
||
const SettingsScreen = ({ navigation }: any) => { | ||
const [hasLeftItem, setHasLeftItem] = useState(false); | ||
|
||
const square1 = (props: { tintColor?: string }) => ( | ||
<View style={{ gap: 8, flexDirection: 'row' }}> | ||
{hasLeftItem && <Square {...props} color="green" size={20} />} | ||
<Square {...props} color="green" size={20} /> | ||
</View> | ||
); | ||
|
||
const square2 = (props: { tintColor?: string }) => ( | ||
<Square {...props} color="red" size={20} /> | ||
); | ||
|
||
useLayoutEffect(() => { | ||
navigation.setOptions({ | ||
headerRight: square1, | ||
headerTitle: undefined, | ||
headerLeft: hasLeftItem ? square2 : undefined, | ||
headerBackTitleVisible: false, | ||
}); | ||
}, [navigation, hasLeftItem]); | ||
|
||
return ( | ||
<SettingsSwitch | ||
label="Left item" | ||
value={hasLeftItem} | ||
onValueChange={setHasLeftItem} | ||
/> | ||
); | ||
}; | ||
|
||
const Stack = createNativeStackNavigator(); | ||
|
||
const App = () => ( | ||
<NavigationContainer> | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="Settings" | ||
component={SettingsScreen} | ||
options={{ | ||
headerTintColor: 'hotpink', | ||
}} | ||
/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
|
||
export default App; |
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
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.
Okay, so we now trigger layout in the native superview (this is one of system views, beyond control of react) every time we receive a new frame from react.
The solution itself is ok & if it helps I'm for it, but do we have understanding why does it not work without this change? Especially that we do not have such code on Paper & I believe it works fine there?
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.
Yeah, it does work fine on paper. It looks like the bounds of the subview are set properly but then the frame is given the old values unless we trigger a re-layout of the superview.
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.
Did you check what happens if you disable view recycling on header subviews in this PR? Im speaking with context of this issue on which we debated earlier today: #2232
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.
This might be the same issue of the views being swapped due to recycling pool working in stack manner.
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.
Turning off recycling does not fix this issue