Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10

Access ListItemComponent outside a ListView

Hello, please could you help me with my list problem ?


Here's the ListItemComponent, it's a DockLayout in which I'm displaying an ImageView and a WebView on top of it. When the content of the webview is loaded, I change the opacity of the imageview to 0 to hide it.
It's working fine.
But when the user click on a page action item, I'm changing the listview layout and I want to show the ImageView only. How can I set the webview opacity to 0 when I'm outside the listitemcomponent ?

Thanks for your help,
Laurent

 

ListItemComponent {
	Container {
		id: cont
		
		bottomPadding: 10
		layout: DockLayout {
		}

		background: Color.White

		ImageView {
			id: imageView
			opacity: 1 
			imageSource: ListItemData.image
			horizontalAlignment: HorizontalAlignment.Center
			verticalAlignment: verticalAlignment.Center
			preferredWidth: cont.ListItem.view.normalLayoutFct() ? 400 : 200
			preferredHeight: cont.ListItem.view.normalLayoutFct() ? 400 : 200			
		}

		ScrollView {
			id: scrollView
			horizontalAlignment: HorizontalAlignment.Center
			verticalAlignment: verticalAlignment.Center
			scrollViewProperties {
				scrollMode: ScrollMode.Both
				pinchToZoomEnabled: true

			}
			preferredWidth: cont.ListItem.view.normalLayoutFct() ? 400 : 200
			preferredHeight: cont.ListItem.view.normalLayoutFct() ? 400 : 200
			
			settings {				
				defaultFontSize: 16 
			}
			
			WebView {
				id: webView
				opacity: 0
				url: ListItemData.url
				settings.devicePixelRatio: 0.75

				onLoadingChanged: {
					if (loadRequest.status == WebLoadStatus.Succeeded && cont.ListItem.view.normalLayoutFct()) {					
						imageView.opacity = 0
						webView.opacity = 1
					}
				}				
			}
		}		
	}
}

 

 

 

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
Curahee
Posts: 224
Registered: ‎01-12-2013
My Device: z30

Re: Access ListItemComponent outside a ListView

I guess you can use a property for this.

 

property int webviewOpacity: 0
property int imageOpacity: 1

ListItemComponent {
	Container {
		id: cont
		
		bottomPadding: 10
		layout: DockLayout {
		}

		background: Color.White

		ImageView {
			id: imageView
			opacity: imageOpacity
			imageSource: ListItemData.image
			horizontalAlignment: HorizontalAlignment.Center
			verticalAlignment: verticalAlignment.Center
			preferredWidth: cont.ListItem.view.normalLayoutFct() ? 400 : 200
			preferredHeight: cont.ListItem.view.normalLayoutFct() ? 400 : 200			
		}

		ScrollView {
			id: scrollView
			horizontalAlignment: HorizontalAlignment.Center
			verticalAlignment: verticalAlignment.Center
			scrollViewProperties {
				scrollMode: ScrollMode.Both
				pinchToZoomEnabled: true

			}
			preferredWidth: cont.ListItem.view.normalLayoutFct() ? 400 : 200
			preferredHeight: cont.ListItem.view.normalLayoutFct() ? 400 : 200
			
			settings {				
				defaultFontSize: 16 
			}
			
			WebView {
				id: webView
				opacity: webviewOpacity
				url: ListItemData.url
				settings.devicePixelRatio: 0.75

				onLoadingChanged: {
					if (loadRequest.status == WebLoadStatus.Succeeded && cont.ListItem.view.normalLayoutFct()) {					
						imageOpacity = 0
						webviewOpacity = 1
					}
				}				
			}
		}		
	}
}

 

Just change the properties to 0 and 1 as you like.

______________________________________________________
beRail: BlackBerry World - GitHub
Mobile Vikings: BlackBerry World - GitHub
Park in Brussels: BlackBerry World
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Access ListItemComponent outside a ListView

It's not possible to access ListItemComponents from outside, but it's possible to bind ListItemComponent's variables to variables defined outside (which likely won't help in this situation).

If your ListView can contain more than one item, it's better to bind everything to dataModel's fields and change the component by updating corresponding dataModel items. Otherwise everything will break during scrolling when ListView is reusing listItemComponents.


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10

Re: Access ListItemComponent outside a ListView

Zmey, it's too bad if I can't access ListItemComponents from outside. But I'll still try Curahee solution...

Twitter : @LaurentKP
My apps
Please use plain text.
Regular Contributor
umairqureshi_6
Posts: 75
Registered: ‎05-31-2013
My Device: 9900
My Carrier: Ufone

Re: Access ListItemComponent outside a ListView

Please use plain text.