11import React , { useMemo } from "react" ;
22import { View , Text , ScrollView , Pressable , ActivityIndicator } from "react-native" ;
3- import { Edit , Trash2 , MoreHorizontal } from "lucide-react-native" ;
3+ import { Edit , Trash2 , MoreHorizontal , ChevronLeft , ChevronRight } from "lucide-react-native" ;
44import { cn } from "~/lib/utils" ;
55import { FieldRenderer } from "./fields/FieldRenderer" ;
66import type { FieldDefinition , FormViewMeta , FormSection , ActionMeta } from "./types" ;
@@ -34,6 +34,16 @@ export interface DetailViewRendererProps {
3434 relatedLists ?: RelatedListConfig [ ] ;
3535 /** Handler when a related record is pressed */
3636 onRelatedRecordPress ?: ( objectName : string , record : Record < string , unknown > ) => void ;
37+ /** Navigate to the previous record */
38+ onPrevious ?: ( ) => void ;
39+ /** Navigate to the next record */
40+ onNext ?: ( ) => void ;
41+ /** Whether there is a previous record available */
42+ hasPrevious ?: boolean ;
43+ /** Whether there is a next record available */
44+ hasNext ?: boolean ;
45+ /** Label indicating position, e.g. "3 of 50" */
46+ positionLabel ?: string ;
3747}
3848
3949export interface RelatedListConfig {
@@ -136,6 +146,69 @@ function RelatedListSection({
136146 ) ;
137147}
138148
149+ /* ------------------------------------------------------------------ */
150+ /* Record Navigator */
151+ /* ------------------------------------------------------------------ */
152+
153+ function RecordNavigator ( {
154+ onPrevious,
155+ onNext,
156+ hasPrevious = false ,
157+ hasNext = false ,
158+ positionLabel,
159+ } : Pick <
160+ DetailViewRendererProps ,
161+ "onPrevious" | "onNext" | "hasPrevious" | "hasNext" | "positionLabel"
162+ > ) {
163+ if ( ! onPrevious && ! onNext ) return null ;
164+
165+ return (
166+ < View className = "flex-row items-center justify-between border-b border-border bg-card px-4 py-2" >
167+ < Pressable
168+ className = { cn (
169+ "flex-row items-center rounded-lg px-3 py-2" ,
170+ hasPrevious ? "active:bg-muted" : "opacity-40" ,
171+ ) }
172+ onPress = { hasPrevious ? onPrevious : undefined }
173+ disabled = { ! hasPrevious }
174+ >
175+ < ChevronLeft size = { 16 } color = { hasPrevious ? "#1e40af" : "#94a3b8" } />
176+ < Text
177+ className = { cn (
178+ "ml-1 text-sm font-medium" ,
179+ hasPrevious ? "text-primary" : "text-muted-foreground" ,
180+ ) }
181+ >
182+ Previous
183+ </ Text >
184+ </ Pressable >
185+
186+ { positionLabel && (
187+ < Text className = "text-xs text-muted-foreground" > { positionLabel } </ Text >
188+ ) }
189+
190+ < Pressable
191+ className = { cn (
192+ "flex-row items-center rounded-lg px-3 py-2" ,
193+ hasNext ? "active:bg-muted" : "opacity-40" ,
194+ ) }
195+ onPress = { hasNext ? onNext : undefined }
196+ disabled = { ! hasNext }
197+ >
198+ < Text
199+ className = { cn (
200+ "mr-1 text-sm font-medium" ,
201+ hasNext ? "text-primary" : "text-muted-foreground" ,
202+ ) }
203+ >
204+ Next
205+ </ Text >
206+ < ChevronRight size = { 16 } color = { hasNext ? "#1e40af" : "#94a3b8" } />
207+ </ Pressable >
208+ </ View >
209+ ) ;
210+ }
211+
139212/* ------------------------------------------------------------------ */
140213/* Main Component */
141214/* ------------------------------------------------------------------ */
@@ -153,6 +226,11 @@ export function DetailViewRenderer({
153226 actions,
154227 relatedLists,
155228 onRelatedRecordPress,
229+ onPrevious,
230+ onNext,
231+ hasPrevious,
232+ hasNext,
233+ positionLabel,
156234} : DetailViewRendererProps ) {
157235 /* ---- Build sections ---- */
158236 const sections : FormSection [ ] = useMemo ( ( ) => {
@@ -224,6 +302,15 @@ export function DetailViewRenderer({
224302 onAction = { onAction }
225303 />
226304
305+ { /* Record navigation (previous / next) */ }
306+ < RecordNavigator
307+ onPrevious = { onPrevious }
308+ onNext = { onNext }
309+ hasPrevious = { hasPrevious }
310+ hasNext = { hasNext }
311+ positionLabel = { positionLabel }
312+ />
313+
227314 < ScrollView
228315 className = "flex-1"
229316 contentContainerClassName = "px-4 pb-8 pt-4"
0 commit comments