fix(Camera): allow partial padding on the root padding prop - #4279
Open
giaBaoJS wants to merge 1 commit into
Open
fix(Camera): allow partial padding on the root padding prop#4279giaBaoJS wants to merge 1 commit into
giaBaoJS wants to merge 1 commit into
Conversation
`CameraStop.padding` was typed as `CameraPadding`, which requires all four
edges, so `padding={{ paddingBottom: 10 }}` failed to compile with TS2739
even though the runtime already supports partial padding: `buildNativeStop`
reads every edge individually and only forwards the ones that are defined.
Widen the prop to `Partial<CameraPadding>`, matching `followPadding` and
`CameraBoundsWithPadding` in the same file. The exported `CameraPadding`
type is unchanged, so this is not a breaking change.
Fixes rnmapbox#3599
giaBaoJS
requested a deployment
to
CI with Mapbox Tokens
August 14, 2026 02:07 — with
GitHub Actions
Waiting
giaBaoJS
requested a deployment
to
CI with Mapbox Tokens
August 14, 2026 02:07 — with
GitHub Actions
Waiting
giaBaoJS
requested a deployment
to
CI with Mapbox Tokens
August 14, 2026 02:07 — with
GitHub Actions
Waiting
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes #3599
CameraStop.paddingis typed asCameraPadding, which declares all four edges as required. So the perfectly reasonablepadding={{ paddingBottom: 10 }}fails to compile — even though the runtime has supported partial padding all along. The type was simply lying about the implementation.buildNativeStopreads each edge independently and forwards only the ones that are actually defined (src/components/Camera.tsx#L331-L353):The fix widens the prop to
Partial<CameraPadding>. This matches two conventions already present in the same file:Camera.tsx:170followPadding?: Partial<CameraPadding>Camera.tsx:223CameraBoundsWithPadding = Partial<CameraPadding> & CameraBoundsThe repo's own example app already assumes this is how
paddingworks —example/src/examples/UserLocation/UserLocationPadding.tsx:19declaresRecord<Alignment, Partial<CameraPadding>>and passes{ paddingBottom: 300 }.The exported
CameraPaddingtype is left untouched, so nothing that consumes it today changes meaning — this is not a breaking change, it only accepts more than it did before.Reproduction and before/after evidence
Per
.github/REPRODUCING.md. This is a compile-time bug, so the reproducer is a type-check: it needs no device, no simulator and no Mapbox token, and it fails on the unfixed build and passes on the fixed one.The reproducer file was placed at the repo root and run through the repo's own gate,
yarn typecheck. It is not committed — it is reproduced in full below.Reproducer —
repro-3599.tsx(repo root)BEFORE the fix —
yarn typecheck, exit code2:That first line is exactly the error reported in #3599.
AFTER the fix —
yarn typecheck, exit code0, no output.The reproducer is not vacuous
A "before red / after green" result is only worth something if the check is capable of going red for the right reason. Two things were verified:
repro-3599.tsxfirst, andyarn typecheckdid report it — so the file is genuinely compiled and not silently excluded bytsconfig.json:@ts-expect-errordirectives after the fix shows the guarded cases are still real errors — only optionality changed, nothing else:Runtime impact
Every consumer of the prop type was checked; a partial object cannot reach a code path that assumes a complete one.
buildNativeStop(Camera.tsx:331-353) is already per-edge!== undefinedguarded, as quoted above.nativeStop(:390-421) only forwards the prop into it.src/web/components/Camera.tsx:170-182gates the whole padding block on all four edges being present before callingbuildMapboxGlPadding. A partial object simply leavesoptions.paddingunset, which is already what{}does today. No partial object can reach Mapbox GL.fitBounds—_fitBounds(:476-525) builds a fully populated_paddingliteral from its ownpaddingConfigargument and never consumes the prop type, so widening cannot affect it.Note on generated docs
yarn generatewas run, as required. One side effect worth flagging: the doc generator cannot expand aPartial<T>, sodocs/Camera.mdnow renders thepaddingprop asPartialinstead of the expanded four-field shape. This is a pre-existing limitation rather than something new —followPaddingalready renders as barePartialfor the same reason. The JSDoc was extended to "Individual edges may be omitted." to compensate. Happy to inline the optional shape literal instead if you would rather keep the expanded table in the docs.Verification
All run at
cbf2a2d(the merge-base) with the change applied:yarn typecheckyarn unittestyarn lintexample→yarn type:checkyarn generateChecklist
CONTRIBUTING.mdyarn generatein the root folder/exampleapp./example)This is a type-only change with no runtime diff, so it is verified by the type-level reproducer above rather than by a device run. The existing
UserLocationPaddingexample already exercises partial padding at runtime.Component to reproduce the issue you're fixing