cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jasondefaoite
Advocate I
Advocate I

Scrolling an image

Hi all,


I have what might be a simple question on image scrolling, but I have tried a number of approaches and can't get it working the way I would like.

I have a screen with a resolution of 640x1136. On this screen I place an image of 1900x900. The idea is that the user can swipe on the screen to scroll across the image. What I have tried ...

- Use a horizontal gallery, setting the width of the gallery to >1900, and the item within the gallery of a similar width. Doesn't work. The part of the image which is currently visible on screen (the initial 640 pixels) is repeated as I scroll.  So the image appears corrupted. Scrolls beautifully though 🙂

If I limit the gallery to a single item (FirstN(gallery,1), i can see the full image in the power apps editor (not corrupted), but it doesn't scroll (even thought the item width is > 640).

Is it possible to have a horizontal gallery item width > screen width?

- Segment the image into smaller widths, and use a horizontal gallery, with each segmented part of the image placed in a separate item (of less than 640 pixels) within the gallery. Works, but alignment will be an issue as the final app has scale to fit enabled and the layout is slightly different on different devices as a result.

- Use an invisible slider control above the image, and tie the image X position to the slider value.  Works, but it has two drawbacks.

1.  Scroll is too fast, as I'm scrolling an image which is three times the width of the screen, using a slider control just under a single screen width

 

2. If the user touches the screen, they adjust the slider position and the image position 'jumps' as the image X position is tied to the slider value.

Ideally i want to measure the amount the slider has moved, and link that value to the Image X position, rather than the actual slider position.

I can set a variable to the initial slider value using the OnSelect property of the slider, then subtracting the current slider value from this initial value, I have the distance the slider moves. Great! But to support multiple swipes across the image, I need a running count of the total distance moved by the slider across multiple adjustments of the slider position, and this is where I am stuck.

I can use the OnChange property of the slider to update a variable with the total distance the slider has moved, but this only updates when the slider is released, but I need this variable updated as the slider is being moved.

 

Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
Jasondefaoite
Advocate I
Advocate I

Ok, again for the benefit of anyone coming here in future. The best way to do this ... 

Insert a vertical container. Set the horizontal Overflow property to Scroll. Set the width to the width of your image.

Inside this container, insert a vertical gallery. Again, set the width as the width of your image. Set the number of items in the gallery to 1 by setting the items property to FirstN(CustomGallerySample,1).

Inside the gallery insert your image, and set the width/height you need (width should match that of the gallery/container)

Now, when using the phone, you can scroll across your image horizontally using standard swipe gestures and as this is in a gallery, you get rubber banding and 60Hz animations of the horizonal movement. 

This is the solution I needed from the start 😉

View solution in original post

7 REPLIES 7
rubin_boer
Super User
Super User

hi @Jasondefaoite here is an idea, it does not give you precisely what you want but may get you in the right direction.

 

set the image width to 1900 this will make the image go out of view. add two icons on the left and right of the screen and to scroll left set the left icon OnSelect to Set(_X,Image5.X-50) , right OnSelect = Set(_X,Image5.X+50) and two others  for up OnSelect = Set(_Y,Image5.Y-50) and down Set(_Y,Image5.Y + 50)  . On the image set the X to _X and the Y to _Y. now you can scroll the image. 

 

Image "Zoomed"

rubin_boer_0-1614947492512.png

 

Select scrolling up

rubin_boer_2-1614947599343.png

 

 

 

Hope this helps

 

First, thank you for taking the time to reply. I actually have tap to move the image already working. However I could see a number of initial users trying to swipe across the image to move it rather than tapping, given their experience with how most native iOS/Android apps work.

I wanted to replace this tap to move with a swipe gesture.

rubin_boer
Super User
Super User

it would be great. upvote the idea and it will def get a mention at the super user meeting A Control element that returns X and Y coordinates... - Power Platform Community (microsoft.com) 😉

Thanks Rubin, upvoted.

I managed to get it working. Solution for reference, I needed to add a timer.

 

Slider onSelect sets initialPositionVariable = Slider.Value. It also sets variableStartTimer = true.
Slider onChange sets the variableStartTimer = false.

Add a timer with a duration of 10, with a start of varibleStartTimer and repeat of varibleStartTimer

 

So far, when we select/touch the slider, the timer starts/repeats until we release the slider. Also with the initial selection of the slider, initialPositionVariable - Slider.Value = 0, and if we move the slider in either direction, initialPositionVariable - Slider.Value will give us the delta.

Finally, we can set the timer's onTimerEnd to set myXvalue = myXvalue - (initialPositionVariable - Slider.Value)
So myXvalue is updated every time the timer loops, adding the delta position to it. 

Tie the image X position to myXvalue. 
Make the slider the size of the screen, and the handle size ~ 600 and make all colors transparent.

If you then swipe right to left on the screen, the image moves left to right.

rubin_boer
Super User
Super User

thats pretty cool 🙂

 

Cheers. One correction, the minimum timer value appears to be 50ms. This equates to being able to update the image position 20 times a second, or 20Hz. Ideally it should be updating at 60Hz. But it works!

Jasondefaoite
Advocate I
Advocate I

Ok, again for the benefit of anyone coming here in future. The best way to do this ... 

Insert a vertical container. Set the horizontal Overflow property to Scroll. Set the width to the width of your image.

Inside this container, insert a vertical gallery. Again, set the width as the width of your image. Set the number of items in the gallery to 1 by setting the items property to FirstN(CustomGallerySample,1).

Inside the gallery insert your image, and set the width/height you need (width should match that of the gallery/container)

Now, when using the phone, you can scroll across your image horizontally using standard swipe gestures and as this is in a gallery, you get rubber banding and 60Hz animations of the horizonal movement. 

This is the solution I needed from the start 😉

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,049)