Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    How Cisco Transforms AI Data Centers

    February 16, 2026

    AT&T reveals its iPhone 16 deals — get up to $1,000 off with an eligible trade-in

    February 16, 2026

    TypeScript 6.0 beta lays the foundation for shifting the codebase from JavaScript to Go

    February 15, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – Why does my page scroll up when I tap on a button?
    iOS Development

    ios – Why does my page scroll up when I tap on a button?

    big tee tech hubBy big tee tech hubJanuary 25, 2026013 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – Why does my page scroll up when I tap on a button?
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    I have a fairly simple view.

    It’s a trip itinerary with two parts:

    1. A horizontally scrolling list of dates at the top of the page.

    2. A vertically scrolling list of days (each day contains many trip stops).

    I’ve added logic for .scrollPosition() so that as the user scrolls the vertical list, the horizontal list can update which day the user is currently active on the page.

    Similarly, when a user taps on a day in the horizontal list at the top of the page, I have it set up to automatically scroll down to that day in the vertical list.

    Here is that code:

    struct TripView: View {
        @Environment(\.dismiss) private var dismiss
        
        @Binding var trip: Trip
    
        @State private var activeDate: String?
    
        var body: some View {
            VStack(spacing: 0) {
                // HORIZONTAL DATE PICKER
                ScrollViewReader { proxy in
                    ScrollView(.horizontal, showsIndicators: false) {
                        LazyHStack(spacing: 16) {
                            ForEach(trip.days, id: \.id) { day in
                                Button(action: {
                                    withAnimation(.spring(duration: 0.3)) {
                                        activeDate = day.date
                                    }
                                }, label: {
                                    VStack(spacing: 2) {
                                        Text(day.date.formatDate(fromFormat: "yyyy-MM-dd", toFormat: "d") ?? "")
                                            .background(activeDate == day.date ? Color.blue : Color.clear)
                                    }
                                })
                                .id(day.date)
                            }
                        }
                    }
                    .onChange(of: activeDate) { oldValue, newValue in
                        print("Active date changed to: \(newValue)")
                        
                        if let newValue {
                            withAnimation {
                                proxy.scrollTo(newValue, anchor: .center)
                            }
                        }
                    }
                }
    
                // VERTICAL CONTENT LIST
                ScrollView {
                    LazyVStack(spacing: 0) {
                        ForEach($trip.days) { $day in
                            TripDayView(
                                tripId: trip.id,
                                day: $day
                            )
                            .id(day.date)
                        }
                    }
                    .scrollTargetLayout()
                }
                .scrollPosition(id: $activeDate, anchor: .top)
            }
        }
    }
    

    The problem I’m facing is inside TripDayView below.

    struct TripDayView: View {
        @EnvironmentObject var tripManager: TripManager
    
        let tripId: Int
        @Binding var day: Day
        
        @State private var showingActionSheet: Bool = false
        
        var body: some View {
            Section {
                headerView
                
                ListStopsView(tripId: tripId, stops: $day.stops)
            }
        }
    
        var headerView: some View {
            VStack(alignment: .leading, spacing: 0) {
                HStack(spacing: 0) {
                    VStack(alignment: .leading, spacing: 0) {
                        Text(day.date.formatDate(fromFormat: "yyyy-MM-dd", toFormat: "EE, MMM d") ?? "")
                    }
                    
                    Spacer()
                    
                    Button(action: {
                        showingActionSheet = true
                    }, label: {
                        Image("Ellipsis Vertical")
                    })
                    .confirmationDialog("", isPresented: $showingActionSheet, titleVisibility: .hidden) {
                        Button("Option 1") {
                            //
                        }
                        
                        Button("Option 2") {
                            //
                        }
                        
                        Button("Option 3") {
                            //
                        }
                    }
                }
            }
        }
    }
    

    When I tap on the Button (that sets showingActionSheet = true), the vertical list in TripView scrolls up when the confirmationDialog is shown.

    What is causing this? How can I fix it?

    It seems to be related to .scrollPosition() because when I comment out that line, it doesn’t scroll up when I tap the button. But I need to keep that functionality.



    Source link

    button iOS page scroll tap
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    Fatal ‘Index out of range’ error when using macOS simulator in Xcode but not when using iOS simulator

    February 15, 2026

    ios – How to persist credit balance in a credit-based AI app when using anonymous sign-in?

    February 14, 2026

    Flutter iOS build failing with CocoaPods platform version errors, while Android works fine

    February 13, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    How Cisco Transforms AI Data Centers

    February 16, 2026

    AT&T reveals its iPhone 16 deals — get up to $1,000 off with an eligible trade-in

    February 16, 2026

    TypeScript 6.0 beta lays the foundation for shifting the codebase from JavaScript to Go

    February 15, 2026

    Is IFS therapy evidence-based — or is it a sham? Does it matter?

    February 15, 2026
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    How Cisco Transforms AI Data Centers

    February 16, 2026

    AT&T reveals its iPhone 16 deals — get up to $1,000 off with an eligible trade-in

    February 16, 2026

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2026 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.