0

I am creating a dynamic GridLayout in Nativescript following the example on there page:

https://docs.nativescript.org/ui/layouts/layout-containers

It allows my to make a GridLayout using javascript, as I need it to be dynamic.

However, I want to put this layout in a ScrollView.

I believe I'm meant to do something like this

const grid = new GridLayout();
const scroll = new ScrollView();  
grid.addChild();

...

scroll.addView(grid);

I constantly get an error saying "addView" is not a function.

Is this the correct method? What 'require("");' do I need for the ScrollView?

Thanks

2 Answers 2

2

You need to import from import { ScrollView } from 'ui/scroll-view';

and it's not addView, available public method is _addView

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks Narendra, so can I only do this in angular? The system is written in javascript, I know how to call import in JS, but will is still be _addView?
You can use require e.g. const scroll = require('../../ui/scroll-view'); and yes method name still will be _addView
So I did: const ScrollView = require("tns-core../ui/scroll-view"); I then did 'const scroll = new ScrollView' - I got error (ScrollView is not a function), i then tried ScrollView._addView(grid) and it said (ScrollView._addView is not a function)
should be var scroll = new ScrollView(); Is there any specific reason you want to add scrollview from code, you can have it in yout html and access it var scrollView = page.getViewById('SCROLL_VIEW_ID')
The way I'm calling the pages in the project require to use code. I finally got the scrollview working with no errors, however I get nothing displayed. Once I go scroll._addView(grid) i did page.content = scroll; And its just blank?
|
1

So just as reference for anyone else in the future.

The _addView() method wouldn't throw any errors, however I couldn't get the scene to actually load or show anything.

If there is a way to load the _addView() correctly then more than happy fo someone to add that comment.

The playground for that method is below:

https://play.nativescript.org/?template=play-js&id=LlsHLd

The way I got it working is by doing the following:

const scrollView = require("tns-core-modules/ui/scroll-view").Scroll-View;
var scrollV = new scrollView();

(Dynamically load a gridlayout)
grid.addChild()
....

scroll.content = grid;
page.content = scroll;

Thanks everyone for the help.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.