react-navigation / react-navigation/react-navigation

Custom component in headerTitle has wrong position

Aperta
#10,840 7 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug library:react-native-screens package:native-stack platform:ios repro provided
Lingua principale
TypeScript
Stelle
24.5k
Fork
5.1k
Merge medio
1g 5h
PR unite (30g)
18

Descrizione

Current behavior

I have following config in navigation (basically I want the title to wrap to two lines if it does not fit)

<Stack.Screen
	name={"ScreenName}
	component={ScreenComponent}
	options={() => ({
		headerTitle: () => (
			<Text
				numberOfLines={2}
				ellipsizeMode="tail"
				adjustsFontSizeToFit
				style={{ marginRight: 64, flex: 1, textAlign: 'center'}}
			>
				Custom header title component
			</Text>
		),
	})}
/>

leads to correct position on iPhone 11 pro max, but wrong on iPhone 14 pro. It's also good on iPhone 13 pro. Don't mind the horizontal alignment, I upgraded to current versions and something works different, works fine on versions I actually use in project.

Snímek obrazovky 2022-09-14 v 18 38 14

Replacing the Text component with simple <Text>Custom header title component</Text>
Snímek obrazovky 2022-09-14 v 18 51 04

In the linked repro, the behavior is different, I will try to identify why, but there's still some issue:

  • after rendering the first screen, the title is at the bottom
  • after navigating, the title on the next screen is in correct centered position
  • after navigation back to the first screen, the title on the first screen is moved to correct centered position
Expected behavior

custom component in headerTitle is rendered same on iPhone 11 and iPhone 14

Reproduction

https://github.com/CptFabulouso/react-navigation-header-issue

Platform
  • Android
  • iOS
  • Web
  • Windows
  • MacOS
Packages
  • @react-navigation/​bottom-tabs
  • @react-navigation/​drawer
  • @react-navigation/​material-bottom-tabs
  • @react-navigation/​material-top-tabs
  • @react-navigation/​stack
  • @react-navigation/​native-stack
Environment
  • I've removed the packages that I don't use
package version
@react-navigation/native ^6.0.12
@react-navigation/bottom-tabs ^6.3.3
@react-navigation/material-top-tabs ^6.2.3
@react-navigation/native-stack ^6.8.0
react-native-safe-area-context ^4.3.3
react-native-screens ^3.17.0
react-native-gesture-handler ^1.10.3
react-native-reanimated 1.13.3
react-native-tab-view ^3.1.1
react-native-pager-view ^5.4.25
react-native 0.66.1

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal repository di riproduzione collegato e riproduci il layout native-stack headerTitle sui dispositivi iOS elencati, concentrandoti sul rendering iniziale e sulle transizioni di navigazione. L’issue è completata quando il titolo dell’header personalizzato su due righe rimane costantemente centrato e posizionato correttamente nei casi iPhone 11 Pro Max, iPhone 13 Pro e iPhone 14 Pro.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
react-native, typescript
Ambito
mobile
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.