Best place to set dgVscroll of DataGrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
j9v6
Posts: 99
Joined: Tue Aug 06, 2019 9:27 am
Contact:

Best place to set dgVscroll of DataGrid

Post by j9v6 » Thu Aug 06, 2020 3:50 pm

Ok, so I have a LiveCode iOS app that's close to completion and I'm adding card transitions to make it look a bit better. I have an issue with setting the dgVscroll on a Data Grid. In simple terms, my app has two cards. Card 1 contains a Data Grid Form which is populated with items from an SQLite database. Tapping an entry navigates to Card 2 which displays an edit screen for the record data of the selected entry. It has a couple of buttons one for Save and one for Cancel.

If you tap Cancel or Save, the appropriate action is performed on the database (i.e do nothing or update the database) and the app goes back to Card 1. When navigating back to Card 1 I want to make sure that the dgVscroll for the Data Grid is in the same position as it was before I navigated away from the card. Incidentally, when you navigate to Card 1 it queries the database and rebuilds the array loaded into the DataGrid so that any data changes made on Card 2 are shown in the Data Grid.

I call my "loadData" routine in the preOpenCard handler of Card 1 and the data is loaded successfully to the Data Grid. However if I also set the dgVscroll in the preOpenCard of Card 1 the Data Grid doesn't scroll to the correct location (well it does on the mac in LiveCode, but not on the iOS simulator or on my iPhone). If I move the set dgVscroll to the openCard handler the Data Grid scrolls to the correct location.... but you see it scroll and I'd like to get it set so that you don't see the Data Grid load & scroll as it looks odd and is visually distracting.

If you "lock screen" as the first instruction in preOpenCard and "unlock screen" as the last instruction of OpenCard then you don't see any scrolling, but all the visual effects are lost (unseen) and you just jump from Card 2 back to Card 1. Ok it works, but it doesn't look good.

My goal is to
Display Card 1 with a populated Data Grid
Navigate (slide) smoothly to Card 2 to show a specific entry
Slide smoothly back to Card 1 to show the list at the previously scrolled position.

Has anyone found a way to retain the visual effects when transitioning from one card to another and also pre-scrolling a Data Grid to the correct (previous) location without seeing the Data Grid actually scroll the data?

Here's what I've tried

Card 1 script - note this will scroll to the correct location in the DataGrid but you will see the DataGrid scroll or jump

Code: Select all

global gScroll -- somewhere to store the current dgVscroll (this is set when with a mouseUp handler on the DataGrid)

on preOpenCard
    loadRecords
end preOpenCard

openCard
    set the dgVscroll of group "DataGrid 1" to gScroll
end openCard

command loadRecords
   -- run some code to load data from database into tArray
   set the dgData of group "DataGrid 1" to tArray
end loadRecords
Card 1 script - note this won't scroll the DataGrid to the correct location - even though you set the dgVscroll

Code: Select all

global gScroll -- somewhere to store the current dgVscroll (this is set when with a mouseUp handler on the DataGrid)

on preOpenCard
    loadRecords
    set the dgVscroll of group "DataGrid 1" to gScroll
end preOpenCard

openCard
    --
end openCard

command loadRecords
   -- run some code to load data from database into tArray
   set the dgData of group "DataGrid 1" to tArray
end loadRecords

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Best place to set dgVscroll of DataGrid

Post by dunbarx » Thu Aug 06, 2020 6:00 pm

Hi.

I do not develop for mobile, so my thoughts may not be pertinent.

As usual.

I do not see any visual effects. Anyway, have you tried locking the screen ("for visual effect" if you do indeed have an effect) before navigating?

Craig

j9v6
Posts: 99
Joined: Tue Aug 06, 2019 9:27 am
Contact:

Re: Best place to set dgVscroll of DataGrid

Post by j9v6 » Sat Aug 08, 2020 9:49 pm

Hi Craig,

Thanks for your feedback. The visual effects aren’t shown above as that code is in the button action of Card 2. The stuff above is code from Card 1. The biggest problem is making the data grid scroll to the desired location without seeing the scroll actually happen. I just want the navigation from card 2 back to card 1 to display the DataGrid at the correct position without watching it shoot up the screen on the mobile device. As mentioned in my question, if you set the dgvscroll of a DataGrid in the preOpenCard the DataGrid doesn’t process it - it just stays at the top. If you set the dgvscroll in openCard then it does work but you see the DataGrid scroll to the offset.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Best place to set dgVscroll of DataGrid

Post by dunbarx » Sun Aug 09, 2020 4:07 am

Hi.

Assuming that mobile does not act differently, and it might, did you try locking the screen as I mentioned?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Best place to set dgVscroll of DataGrid

Post by jacque » Sun Aug 09, 2020 9:16 pm

I think you'll need to do all the changes in card 2, like this:

Code: Select all

lock screen for visual effect
send "loadRecords" to cd 1
set the dgVscroll of group "DataGrid 1" of cd 1 to gScroll
go cd 1
unlock screen with visual effect "whatever"
Since it doesn't scroll correctly in preOpenCard I'm not sure it will work this way either but it's worth a try.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

j9v6
Posts: 99
Joined: Tue Aug 06, 2019 9:27 am
Contact:

Re: Best place to set dgVscroll of DataGrid

Post by j9v6 » Sun Aug 09, 2020 10:21 pm

I’ve tried locking the screen before the loadData and set dgvscrol then unlocking afterwards and you can still see the DataGrid contents scroll

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Best place to set dgVscroll of DataGrid

Post by jacque » Sun Aug 09, 2020 11:42 pm

j9v6 wrote:
Sun Aug 09, 2020 10:21 pm
I’ve tried locking the screen before the loadData and set dgvscrol then unlocking afterwards and you can still see the DataGrid contents scroll
Did you do it on card 2?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

j9v6
Posts: 99
Joined: Tue Aug 06, 2019 9:27 am
Contact:

Re: Best place to set dgVscroll of DataGrid

Post by j9v6 » Mon Aug 10, 2020 10:44 am

Hi Jacque,

That's an interesting idea... I'll give it a try.

At the moment I have it setup this way. The transition from Card 2 to Card 1 works ok, but then even with the lock screen instructions, the data grid visibly jumps to the correct scroll position.

Card 2 script (triggered when I press the cards "Cancel" button)

command backAction
visual effect "push right" very fast
go to card "card 1"
end backAction

Card 1 script has this right now:

global gScroll -- somewhere to store the current dgVscroll (this is set when with a mouseUp handler on the DataGrid)

on preOpenCard
--
end preOpenCard

openCard
lock screen
loadRecords
set the dgVscroll of group "DataGrid 1" to gScroll
unlock screen
end openCard

command loadRecords
-- run some code to load data from database into tArray
set the dgData of group "DataGrid 1" to tArray
end loadRecords

Post Reply