HOW to properly Add a Dynamic View e.g WebView

nativescriptcore

#1

i tried this but it throws an error “Wv.addChild(wv) is not a function”
var wv = new webViewModule.WebView(); wv.src = "https://www.pinterest.com/"; var Wv = page.getViewById('wbv'); Wv.addChild(wv);
Please help @manojdcoder


#2

To which component you are actually trying to add the newly created WebView? wbv must be a layout for your code to work.


#3

yes it is a Gridlayout, i tried stacklayout still throws error, its like addChild() doesn’t exist anymore in {N} 3.4.3 can you pliz show how its done in playground! because i spent 5hrs in Playground to no avail, even the playground editor(or VS code editor) doesn’t auto complete the addChild() function


#4

It seems to work perfectly fine, you may refer the example by @multishiv19 which is also listed in NativeScript Snacks.

If you still face issues, I would recommend you to share your example where we can reproduce the issue.


#5

here is the solution How to Add Dynamic Views i found out that you CAN’T add a dynamic view if the View Element(parent) is empty, if you see in my snack from playground, the Gridlayout has a child Lable(it could have been anything) without which it Throws an error

<Page loaded="pageLoaded" class="page" navigatedTo="navigatingTo" xmlns="http://www.nativescript.org/tns.xsd">

	<ActionBar title="Home" class="action-bar">
	</ActionBar>
	<GridLayout id="wv">
		<Label/>//this one  will be replaced by the WebView i think
	</GridLayout>
</Page>

#6

As it’s a GridLayout, did you try designated methods there?

Docs: https://docs.nativescript.org/cookbook/ui/layouts/grid-layout

Example: https://play.nativescript.org/?template=play-tsc&id=hdLZ8u&v=2


#7

The point is i am adding the dynamic view(WebView) into the Gridlayout which is declared in xml, if there is no other view in the Gridlayout an error is thrown but if there is something else it works!!!