Giter Club home page Giter Club logo

nativescript-pulltorefresh's Introduction

NativeScript plugin to use Pull to Refresh on any view.


UPDATE

This plugin has been migrated to nativescript-community as of June 24, 2021. The repo can be found here: https://github.com/nativescript-community/ui-pulltorefresh

Installation

NativeScript 7+:

ns plugin add @nstudio/nativescript-pulltorefresh

NativeScript prior to 7:

tns plugin add @nstudio/[email protected]

Sample Screen

Android iOS
Android Sample iOS Sample

Usage

NativeScript Core

XML

<page xmlns="http://schemas.nativescript.org/tns.xsd"
      xmlns:PullRefresh="@nstudio/nativescript-pulltorefresh"
      loaded="pageLoaded">
    <PullRefresh:PullToRefresh refresh="refreshList" indicatorFillColor="#fff000" indicatorColor="#3489db">
        <list-view items="{{ users }}">
            <list-view.itemTemplate>
                <label text="{{ name }}" row="0" col="1"textWrap="true" class="message" />
            </list-view.itemTemplate>
        </list-view>
    </PullRefresh:PullToRefresh>
</page>

JS

function refreshList(args) {
  // Get reference to the PullToRefresh component;
  var pullRefresh = args.object;

  // Do work here... and when done call set refreshing property to false to stop the refreshing
  loadItems().then(
    (resp) => {
      // ONLY USING A TIMEOUT TO SIMULATE/SHOW OFF THE REFRESHING
      setTimeout(() => {
        pullRefresh.refreshing = false;
      }, 1000);
    },
    (err) => {
      pullRefresh.refreshing = false;
    }
  );
}
exports.refreshList = refreshList;

Angular NativeScript

import { registerElement } from "nativescript-angular/element-registry";
registerElement("PullToRefresh", () => require("@nstudio/nativescript-pulltorefresh").PullToRefresh);

refreshList(args) {
         const pullRefresh = args.object;
         setTimeout(function () {
            pullRefresh.refreshing = false;
         }, 1000);
    }

HTML

<PullToRefresh
  (refresh)="refreshList($event)"
  indicatorFillColor="#fff000"
  indicatorColor="#3489db"
>
  <ListView [items]="itemList">
    <template let-item="item">
      <label [text]="item.id"></label>
    </template>
  </ListView>
</PullToRefresh>

NativeScript Vue

import Vue from 'nativescript-vue';

Vue.registerElement(
  'PullToRefresh',
  () => require('@nstudio/nativescript-pulltorefresh').PullToRefresh
);

Component

<template>
  <Page>
    <PullToRefresh
      @refresh="refreshList"
      indicatorFillColor="#fff000"
      indicatorColor="#3489db"
    >
      <ListView for="item in listOfItems" @itemTap="onItemTap">
        <v-template>
          <!-- Shows the list item label in the default color and style. -->
          <label :text="item.text" />
        </v-template>
      </ListView>
    </PullToRefresh>
  </Page>
</template>

<script>
export default {
  methods: {
    refreshList(args) {
      var pullRefresh = args.object;
      setTimeout(function () {
        pullRefresh.refreshing = false;
      }, 1000);
    },
  },
};
</script>

Properties

  • refresh : function required
  • refreshing: boolean - Notifies the widget that the refresh state has changed.
  • indicatorFillColor: Color - the color of the indicator background fill.
  • indicatorColor: Color - the color of the indicator itself.

nativescript-pulltorefresh's People

Contributors

ahalls avatar bradmartin avatar catchabus avatar davidsandoz avatar dlucidone avatar farfromrefug avatar hettiger avatar hypery2k avatar jofftiquez avatar leocaseiro avatar manojdcoder avatar matt4446 avatar mn-martin avatar nathanaela avatar nathanwalker avatar peterstaev avatar ycherniavskyi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nativescript-pulltorefresh's Issues

this.content is undefined

I have tried to use the current version of nativescript-pulltorefresh with the helloworld-ng template. While compiling the typescript I get the Cannot find name 'UIRefreshControl' error, but I let the compiler ignore it. But during the runtime, I get following error:
TypeError: undefined is not an object (evaluating 'this.content.ios') ORIGINAL STACKTRACE: onLoaded@file:///app/tns_modules/nativescript-pulltorefresh/pulltorefresh.js:60:25
It seems, that it comes from this part of pulltorefresh.ios.ts:

if (this.content.ios instanceof UIScrollView) {
    // Ensure that we can trigger the refresh, even if the content is not large enough
    this.content.ios.alwaysBounceVertical = true;

    this.content.ios.addSubview(this._refreshControl);
}

This is my app.component.ts.

If I wrap it into if(this.content != undefined) { [...] }, the runtime error is solved, but I get only the list view..

Thanks in advance!

EDIT:
If I change the line in app.component.ts to:
registerElement("PullToRefresh", require('nativescript-pulltorefresh').PullToRefresh);
I get TypeError: undefined is not a constructor (evaluating 'new viewClass()')

app:runsbg after updating to nativescript 6

after updating I am facing this problem kindly help to fix this.
Host O/s : Ubuntu
✔ Your ANDROID_HOME environment variable is set and points to correct directory.
✔ Your adb from the Android SDK is correctly installed.
✔ The Android SDK is installed.
✔ A compatible Android SDK for compilation is found.
✔ Javac is installed and is configured properly.
✔ The Java Development Kit (JDK) is installed and is configured properly.
✔ Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.
✔ Getting NativeScript components versions information...
✔ Component nativescript has 6.0.1 version and is up to date.
✔ Component tns-core-modules has 6.0.1 version and is up to date.
✔ Component tns-android has 6.0.0 version and is up to date.
✔ Component tns-ios has 6.0.1 version and is up to date.

==============package.json==================
{
"name": "Support-App",
"version": "1.0.0",
"description": "A customer support",
"author": "",
"license": "MIT",
"nativescript": {
"id": "org.nativescript.application",
"tns-ios": {
"version": "6.0.1"
},
"tns-android": {
"version": "6.0.0"
}
},
"dependencies": {
"@vue/devtools": "^5.0.6",
"axios": "^0.19.0",
"nativescript-cardview": "^3.2.0",
"nativescript-fancyalert": "^3.0.8",
"nativescript-feedback": "^1.3.9",
"nativescript-fonticon": "^2.0.0",
"nativescript-permissions": "^1.3.6",
"nativescript-phone": "^1.4.0",
"nativescript-pulltorefresh": "^2.3.0",
"nativescript-socketio": "^3.2.1",
"nativescript-theme-core": "^1.0.6",
"nativescript-toast": "^2.0.0",
"nativescript-toasty": "^1.3.0",
"nativescript-ui-dataform": "^5.0.0",
"nativescript-ui-sidedrawer": "7.0.0",
"nativescript-vue": "^2.3.0",
"nativescript-vue-devtools": "^1.2.0",
"tns-core-modules": "^6.0.1",
"vuex": "^3.0.1"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-loader": "^8.0.2",
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"clean-webpack-plugin": "^0.1.19",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^1.0.0",
"lazy": "1.0.11",
"nativescript-dev-webpack": "1.0.1",
"nativescript-vue-template-compiler": "^2.3.0",
"nativescript-worker-loader": "^0.9.6-next-2019-07-16-195451-01",
"node-sass": "^4.9.2",
"sass-loader": "^7.1.0",
"terser-webpack-plugin": "^1.1.0",
"vue-loader": "^15.7.1",
"webpack": "^4.36.1",
"webpack-bundle-analyzer": "~2.13.1",
"webpack-cli": "^3.3.6"
}
}

======npm global===============
+-- @vue/[email protected]
+-- @vue/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

======java version=====
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK 64-Bit Server VM (build 25.212-b03, mixed mode)
====java home===
/usr/lib/jvm/java-8-openjdk-amd64

Typescript Error While Registering PullToRefresh In NG2 App

To use PullToRefresh in angular 2 app, when we try to register PullToRefresh by registerElement('PullToRefresh', () => PullToRefresh);. Typescript compiler gives error: '() => typeof PullToRefresh' is not assignable to parameter of type '() => ViewClass'.

The error is due to in definition file, extending PullToRefresh by ContentView is missing.

So extending PullToRefresh by ContentView in definition file will fix this.

import { ContentView } from 'ui/content-view';

export declare class PullToRefresh extends ContentView {
...
}

Pan Event Question - is it bubbled up?

I'm not certain how the events get bubbled in NativeScript or NativeScript-Angular so may not be your problem ;-)

I have the pull to refresh on most of my pages but if I show the most irrelevant one (feels quite hypnotic):
refresh-pointless-page

On the stackpanel behind the pull-to-refresh I'm looking for the pan events as I want to make the aside left or aside right show depending if the user drags over a threshold left or right.

Panning on the element above (nav) I can get the events (nav is still a child of center content in this case like the pull-to-refresh).

JS: =Debug===============
JS: 2016-05-23T23:19:51.117Z: Pan centerContent delta: [-4.6382293701171875, 0.6852951049804688] state: 2
JS: ======================
JS: =Debug===============
JS: 2016-05-23T23:19:51.134Z: Pan centerContent delta: [-7.109344482421875, 1.5095863342285156] state: 2
JS: ======================
JS: =Debug===============
JS: 2016-05-23T23:19:51.150Z: Pan centerContent delta: [-9.58441162109375, 1.5095863342285156] state: 2
JS: ======================
JS: =Debug===============
JS: 2016-05-23T23:19:51.167Z: Pan centerContent delta: [-9.58441162109375, 1.5095863342285156] state: 3

On the elements representing aside left I can get them as well.

JS: =Debug===============
JS: 2016-05-23T23:27:09.866Z: Pan asideLeft delta: [67.61468505859375, 7.176422119140625] state: 2
JS: ======================
JS: =Debug===============
JS: 2016-05-23T23:27:09.886Z: Pan asideLeft delta: [65.71446228027344, 5.87274169921875] state: 2
JS: ======================
JS: =Debug===============
JS: 2016-05-23T23:27:09.909Z: Pan asideLeft delta: [65.71446228027344, 5.87274169921875] state: 3
JS: ======================

But panning on any content in the pull-to-refresh there is a deathly silence, except for the wiggling of the pull to refresh. Any ideas?

Cannot read property 'SwipeRefreshLayout' of undefined

I am using Angular Nativescript and the app is giving me the following error when a try to access the template that use this tool:

ERROR Error: Uncaught (in promise): TypeError: Could not load view for: PullToRefresh.TypeError: Cannot read property 'SwipeRefreshLayout' of undefined
 at DebugRenderer2.createElement (file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:30492:36)
 at createElement (file:///data/data/org.nativescript.preview/files/app/tns_modules/@angular/core/bundles/core.umd.js:28524:31)
 at createViewNodes (file:///data/data/org.nativ...
 at ViewUtil.createView (file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/angular/view-util.js:214:44)
 TypeError: Could not load view for: PullToRefresh.TypeError: Cannot read property 'SwipeRefreshLayout' of undefined
 at NativeScriptRenderer.createElement (file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/angular/renderer.js:138:30)
 at Object.getViewClass (file:///data/data/org.nativescript.preview/files/app/tns_modules/@nativescript/angular/element-registry.js:84:15)

in main.ts i have:

import { registerElement } from "nativescript-angular/element-registry";
registerElement("PullToRefresh", () => require("nativescript-pulltorefresh").PullToRefresh);

in the template:

<StackLayout class="page__content">
    <Label class="page__content-icon fas" text="&#xf002;"></Label>
    <PullToRefresh (refresh)="onPull($event)"> 
        <ListView class="list-group" [items]="this.noticias.buscar()" (itemTap)="onItemTap($event)"
            style="height:1250px">
            <ng-template let-x="item">
                <FlexboxLayout flexDirection="row" class="list-group-item">
                    <Image src="res://icon" class="thumb img-circle"></Image>
                    <Label [text]="x" class="list-group-item-heading" verticlaAligment="center"
                        style="width: 60%"></Label>
                </FlexboxLayout>
            </ng-template>
        </ListView>
    </PullToRefresh>
</StackLayout>

and in the component

onPull(e) {        
        console.log(e);        
        const pullRefresh = e.object;        
        setTimeout(() => {            
            // this.resultados.push("xxxxxxx");            
            pullRefresh.refreshing = false;        
        }, 2000); 
    } 

I searched on the web and found this post with what is seems to be the same problem:
https://stackoverflow.com/questions/63365237/error-in-nativescript-pulltorefresh-android-cannot-read-property-swiperefres

Support for RadListView?

I have switched from regular ListView to RadListView recently because it's just more customizable. However, I lost this plugin while doing so because it is complaining about there being no ScrollView within. I know that there is already a pull-to-refresh feature in RadListView, but it is clumsy and destroys the user experience. The developers for Telerik-UI don't answer issues very often either...

I'm only asking for this if it's a simple task to fix. Otherwise, I'll find other options :)

Thanks in advance

iOS bounce up on refresh and no animation

Hi guys, I am using plugin with wrapping SrcollView like on example below:

<GridLayout columns="*" rows="*, auto" class="page-content">   
    <PullRefresh:PullToRefresh refresh="refreshList">
        <ScrollView height="100%" tap="clearTextfieldFocus">

          <!-- My content with Grid Layouts etc.  -->

        </ScrollView>
    </PullRefresh:PullToRefresh>
</GridLayout>

This works perfect on Android but does not work fine on iOS for some reason. Pull down refreshes the content (calls function on refresh), what is fine. During pulling down there is no animation displayed and after releasing it page bounces up for 100px (+- 30). Like it adds margin-top: -100 after refresh is done. Did anyone had this problem?

Indicator Color

Is there a way to change the indicator color on this? I added to the css

ActivityIndicator {
 color: white;
}

but that did effect the pull to refresh indicator.

Angular2 version of pulltorefresh

I want to add your component to my {N} Angular app.

and added this in my component ts file.

import { registerElement, ViewClass } from "nativescript-angular/element-registry";

registerElement("PullToRefresh", () => {
    var viewClass = require("nativescript-pulltorefresh").PullToRefresh;
    return viewClass;
});

in the view page used it like that

   <pullToRefresh>
        <ListView [items]="groceryList" row="2" class="small-spacing" [class.visible]="listLoaded">
            <template let-item="item">
                <Label [text]="item.name" class="medium-spacing"></Label>
            </template>
        </ListView>
    </pullToRefresh>

It works and refresh spinner is shown on the top of the list when you pull down. But it should somehow trigger a method. lets suppose method name is

refreshList(){}

how will I use it from the view?

ios: pulltorefresh with angular component causes Error

The following is pseudo-code of what the angular 5 looks like.

Pull to refresh currently works with this setup in android but not ios.

The following error occurs:

JavaScript error:
file:///app/bundle.js:1:822578: JS ERROR Error: Content must inherit from either UIScrollView, UIWebView or WKWebView!

The top component has the following code:

<PullToRefresh (refresh)="refreshList($event)" class="refresh-pull">
        <app-component-with-list></app-component-with-list>
</PullToRefresh>

Inside of app-component-with-list:

<ListView [items]="stuffItems">
        <ng-template *ngIf="condition">
                <StackLayout>
                     (Stuff for the list)
                </StackLayout>
        </ng-template>
</ListView>

Not working on Android

I am running the plugin fine on iOS, but on Android I just get this while trying to pull down:
screenshot_20170626-113528

This is my XML code:

<Page xmlns="http://schemas.nativescript.org/tns.xsd"  xmlns:sd="nativescript-telerik-ui/sidedrawer" xmlns:PullRefresh="nativescript-pulltorefresh" class="page" actionBarHidden="true" xmlns:map="nativescript-mapbox" loaded="pageLoaded" xmlns:x="nativescript-statusbar" backgroundSpanUnderStatusBar="true" backgroundColor="#182126">
    <sd:RadSideDrawer id="sideDrawer" drawerLocation="left">
        <!-- side drawer content -->
        <sd:RadSideDrawer.drawerContent>
            <GridLayout rows="*" class="sidedrawer-left">

                <GridLayout rows="*" class="sidedrawer-content">
                    <PullRefresh:PullToRefresh refresh="refreshList">
                        <list-view id="pilotList" items="{{ activeList }}" class="list-pilots" itemTap="listViewItemTap">
                            <list-view.itemTemplate  class="list-pilots">
                                <GridLayout columns="*,*2,auto"  class="list-pilots">
                                    <Image src="{{ listPhoto }}" col="0" class="listPhoto" />
                                    <Image src="{{ listIcon }}" col="0" class="listIcon" />
                                    <Label text="{{ listNick }}" col="1"  class="listNick" />
                                    <Label text="{{ listDistance + listMiles + distHeading}}" col="2" class="listDistance" />
                                    <Label text="{{ listAltitude }}" col="1"  class="listAltitude" />
                                    <Label text="{{ listHeading }}" col="1"  class="listHeading" />
                                    <Label text="{{ listSpeed }}" col="2"  class="listSpeed" />                              
                                </GridLayout>
                            </list-view.itemTemplate>
                        </list-view>
                    </PullRefresh:PullToRefresh>
                </GridLayout>
            </GridLayout>
        </sd:RadSideDrawer.drawerContent>

and the JS code for the pulling control:

function refreshList(args) {
    console.log("Pulling to refresh...")
    var pullRefresh = args.object;
    cleanView()
        // ONLY USING A TIMEOUT TO SIMULATE/SHOW OFF THE REFRESHING
        setTimeout(function () {
            pullRefresh.refreshing = false;
        }, 1000);
}
exports.refreshList = refreshList;

The CleanView function only sorts the table for the list view.

Any ideas?

exception with version 3

I'm using nativescript with the vue template, and trying to use nativescript-pulltorefresh gives me the following error on startup:

JS: TypeError: Could not load view for: nativepulltorefresh. TypeError: _nativescript_core__WEBPACK_IMPORTED_MODULE_0__.Property is not a constructor TypeError: _nativescript_core__WEBPACK_IMPORTED_MODULE_0__.Property is not a constructor
JS:     at Module.../node_modules/@nstudio/nativescript-pulltorefresh/pulltorefresh-common.js (file: node_modules\@nstudio\nativescript-pulltorefresh\pulltorefresh-common.js:5:34)
JS:     at __webpack_require__ (file: app\webpack\bootstrap:750:0)
JS:     at fn (file: app\webpack\bootstrap:120:0)
JS:     at Module.<anonymous> (file: node_modules\@nstudio\nativescript-pulltorefresh\pulltorefresh.android.js:1:0)
JS:     at Module.../node_modules/@nstudio/nativescript-pulltorefresh/pulltorefresh.js (file:///data/data/com.loytec.lweb804/files/app/vendor.js:54135:30)
JS:     at __webpack_require__ (file: app\webpack\bootstrap:750:0)
JS:     at fn (file: app\webpack\bootstrap:120:0)
JS:     at Object.resolver (file:///data/data/co...
System.err: An uncaught Exception occurred on "main" thread.
System.err: Unable to start activity ComponentInfo{com.loytec.lweb804/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreate failed
System.err: TypeError: Cannot read property 'setAttribute' of undefined

tns info output:

√ Getting NativeScript components versions information...
√ Component nativescript has 6.8.0 version and is up to date.
√ Component tns-core-modules has 6.5.15 version and is up to date.
√ Component tns-android has 6.5.3 version and is up to date.
√ Component tns-ios has 6.5.2 version and is up to date.

Wrong version being downloaded by default

tns plugin add @nstudio/nativescript-pulltorefresh
command by default is installing v3.0.0 which I'm not even seeing in the release section. This of course causes the app to crash with error

> Module '@nstudio/nativescript-pulltorefresh' not found for element '@nstudio/nativescript-pulltorefresh:PullToRefresh'.

tns plugin add @nstudio/[email protected] works fine which is the latest version currently. Not sure where its puling 3.0.0 from.

Not working with webview on android, for ios works fine

I have integrated this plugin with nativescript webview, i wants to refresh page inside webview
While scrolling down, page is getting refreshed, but its affecting to webview CSS for modal and some angular components

Showing black background behind modal popup

Please provide solution

Can't find UIRefreshControl in pulltorefresh.d.ts

Hello @bradmartin

I'm contacting you again because I have this little error in the file I mentioned in the title.
I know UIRefreshControl is a class used in iOS but in the file, the compiler can't seem to recognize it. Do I need a require somewhere ?

Thank you again

Not working on iOS onLoaded or programmatically

Hello! This plugin works perfect for all cases except for the one I'm going to describe.

I want to be able to fire the "refreshing" property programmatically whenever I want. For Android works perfect, but for iOS it doesn't work.

I'm using nativescript-vue and doing the following:

  • This is the view
<PullToRefresh ref="pullToRefresh" @refresh="onRefresh" row="1" col="0" color="red">
    <ListView for="item in listOfItems" @itemTap="onTap">
        <v-template>
            <Label text="item.text" />
        </v-template>
    </ListView>
</PullToRefresh>
  • This is where I handle the event
onRefresh(args) {
    let pullRefresh = args.object;
    setTimeout(function() {
        pullRefresh.refreshing = false;
    }, 2000);
}
  • Then I have a "loaded" event on the Page tag that will fire once the page is loaded and the following function will handle the event
let pullRefresh = this.$refs.pullToRefresh.nativeView;
pullRefresh.refreshing = true;
setTimeout(function() {
    pullRefresh.refreshing = false;
}, 2000);

As you can see I'm getting the nativeView of pull to refresh and changing the refreshing property programatically. It works but on iOS the color I applied to the ActivityIndicator is lost. Now If I apply the same logic to a button that fires this last function then on iOS it doesn't work at all, the ListView won't scroll itself and it won't display the ActivityIndicator.

Changelog for 2.0.0 ?

Hello,

is there some sort of changelog or upgrade guide to migrate to the latest version of this package?

Vue PullToRefresh Docs

In my experience, i think this docs is more usefull, this is because

  • not everyone would use their parent view as PullToRefresh
  • I encountered errors while trying to use it

I found the solution and maybe you can test (and obviously update the docs 💯 )

Basically main idea is to wrap PullToRefresh with StackLayout

<template>
    <Page>
        <ActionBar title="App's ActionBar" class="action-bar" />

        <StackLayout>
            <PullToRefresh @refresh="refreshList">
                <ListView class="list-group" for="item in items" @itemTap="itemTap">
                    <v-template>
                        <StackLayout class="list-group-item">

                           // CODE HERE

                        </StackLayout>
                    </v-template>
                </ListView>
            </PullToRefresh>

        </StackLayout>
            

    </Page>
</template>

Install through tns-cli

Hi, thanks for this plugin.

I was wondering why not install using the cli?
tns plugin add nativescript-pulltorefresh

Update
It worked for me

Layout issue with NativeScript 3.2

Layout not working when PullToRefresh used, below is my code

<GridLayout xmlns="http://schemas.nativescript.org/tns.xsd"
    xmlns:PullRefresh="nativescript-pulltorefresh" class="page-content" loaded="onLoaded">
    <PullRefresh:PullToRefresh refresh="refreshList">
    	<Label class="page-icon fa" text="&#xf015;"></Label>
    	<Label class="page-placeholder" color="#000" text="Lorem ipsum irure ex ad ut ad cillum veniam in ea tempor nulla ad dolore consectetur dolore est ut cillum dolore irure aliqua in."></Label>
    </PullRefresh:PullToRefresh>
</GridLayout>

Expected:

screenshot_2017-09-14-20-45-45

What I got:

screenshot_2017-09-14-20-48-31

When PullRefresh:PullToRefresh is commented everything works fine.

Not working on Latest NativeScript

Using NativeScript + Angular. Am I missing something?

CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1091:24: ERROR Error: Uncaught (in promise): Error: Content must inherit from UIScrollView!

<FlexboxLayout>
<PullToRefresh (refresh)="refreshList($event)">
  <ListView *ngIf="feed || followFeed"
            [items]="cacheKey === 'main' ? recentFeed[filterMap['']] : followFeed[filterMap['']]"
            class="list-group"
            (loadMoreItems)="onScrollDown()">
    <ng-template let-item="item">
      <feed-card></feed-card>
    </ng-template>
  </ListView>
</PullToRefresh>
</FlexboxLayout>
import { registerElement } from 'nativescript-angular/element-registry';
registerElement('PullToRefresh', () => require('nativescript-pulltorefresh').PullToRefresh);

  public refreshList(args) {
    var pullRefresh = args.object;
    this.updateFeed();
    setTimeout(function () {
      pullRefresh.refreshing = false;
    }, 1000);
  }

nativescript-vue

How can I make it work with nativescript-vue?

So far I have put this at the top of my file:

const PullToRefresh = require('nativescript-pulltorefresh');
Vue.registerElement('PullToRefresh', () => require('nativescript-pulltorefresh').PullToRefresh);

and then I have a stacklayout between the PullToRefresh Tags.
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:PullRefresh="nativescript-pulltorefresh">
      <PullRefresh:PullToRefresh refresh="refreshList">
            <StackLayout>...</StackLayout>
      <PullRefresh:PullToRefresh />
</Page>

List View cant scroll up

Scrolling the list view is ok, but when I am trying to scroll back up to the top, The refresher comes up. Trying to scroll back up is being interpreted as a refresh command. The refresher should come up when i reach the top, and then pull down.

Crashes app on android.

I created this repo (a bare hello world template) to demonstrate this bug:
https://github.com/davecoffin/PullToRefresh-Android-Bug

In a nutshell though:

// main-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:PullRefresh="nativescript-pulltorefresh"  navigatingTo="onNavigatingTo" class="page">
    <Page.actionBar>
        <ActionBar title="My App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>
    <GridLayout>
        <PullRefresh:PullToRefresh refresh="refresh">
            <ScrollView>
                <Label text="sup" />
            </ScrollView>
        </PullRefresh:PullToRefresh>
    </GridLayout>
</Page>
// main-page.js
var createViewModel = require("./main-view-model").createViewModel;
function onNavigatingTo(args) {
    var page = args.object;
    page.bindingContext = createViewModel();
}
exports.refresh = function(args) {
    console.log('done');
}
exports.onNavigatingTo = onNavigatingTo;

and the error is:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to resume activity {org.nativescript.AndroidTest/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
Calling js method onCreateView failed

Error: java.lang.NullPointerException
    android.widget.TextView.setTextColor(TextView.java:3260)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
    com.tns.Runtime.callJSMethod(Runtime.java:1047)
    com.tns.Runtime.callJSMethod(Runtime.java:1028)
    com.tns.Runtime.callJSMethod(Runtime.java:1018)
    com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
    android.app.Fragment.performCreateView(Fragment.java:2352)
    android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
    android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
    android.app.BackStackRecord.run(BackStackRecord.java:815)
    android.app.F

Class not found android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener

After I've added your plugin to my xml file. I've got following error:
[19-08-26 09:42:20.521] (CLI) Exception in thread "main" [19-08-26 09:42:20.528] (CLI) java.lang.RuntimeException: Class not found android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener at org.nativescript.staticbindinggenerator.Generator.getClass(Generator.java:549) at org.nativescript.staticbindinggenerator.Generator.getInterfacesFromCache(Generator.java:532) at org.nativescript.staticbindinggenerator.Generator.writeBinding(Generator.java:283) at org.nativescript.staticbindinggenerator.Generator.generateBinding(Generator.java:171) at org.nativescript.staticbindinggenerator.Generator.processRows(Generator.java:234) at org.nativescript.staticbindinggenerator.Generator.generateBindings(Generator.java:121)
Note that I'm using latest version of Nativescript (6.0)

My xml code is:
`

<ActionBar class="action-bar">
    <!-- 
    Use the NavigationButton as a side-drawer button in Android
    because ActionItems are shown on the right side of the ActionBar
    -->
    <NavigationButton ios:visibility="collapsed" icon="res://menu" tap="onDrawerButtonTap"></NavigationButton>
    <!-- 
    Use the ActionItem for IOS with position set to left. Using the
    NavigationButton as a side-drawer button in iOS is not possible,
    because its function is to always navigate back in the application.
    -->
    <ActionItem icon="res://navigation/menu" android:visibility="collapsed" tap="onDrawerButtonTap" ios.position="left">
    </ActionItem>
    <Label class="action-bar-title" text="Home"></Label>
</ActionBar>

<PullRefresh:PullToRefresh refresh="{{refreshList}}" id="pullToRefresh">
    <GridLayout class="page-content">
        <Label class="page-icon fa" text="&#xf015;"></Label>
        <Label class="page-placeholder" text="{{ data.today }}"></Label>
    </GridLayout>
</PullRefresh>
`

Question: Using in NS angular project

Tried this layout in NS angular project and it didn't work.

<ScrollView>
<StackLayout>
<PullToRefresh refresh="load()">
... 
</PullToRefresh>
</StackLayout>
</ScrollView>

Is there any declaration in NgModule required to use this plugin ?

Thanks

Cannot scroll ListView up

Not sure if this is intentional but I have setup a ListView with some images and labels inside an Android app. Without PullToRefresh I can scroll up and down the list. After adding the PullToRefresh however I can only scroll down. Scrolling up immediately triggers a refresh gesture. Instead I expected to be able to scroll all the way up to the top of the ListView before the refresh gesture kicks in.

Alternatives to ListView

Is it possible to use PulltoRefresh with anything other ListView?

I'd love to create a grid that can use PullToRefresh rather than a vertical list.

I'm using the GridView plugin to create a scrollable grid and would like to use PullToRefresh.

If this isn't possible, doesn't anyone know of any tutorials that could help replicate the pull to refresh
functionality without this plugin?

PullRefresh:PullToRefresh around simple <Label /> crashes on Android

I have a page composed by non-list views. The PullToRefresh plugin works on iOS but crashes on Android. Does that mean this plugin not support this kind of page? If yes, then non-list pages would cry.

<Page class="page"
    navigatingTo="onNavigatingTo"  
    xmlns="http://schemas.nativescript.org/tns.xsd"
    xmlns:PullRefresh="nativescript-pulltorefresh">

    <PullRefresh:PullToRefresh refresh="onRefresh">
        <ScrollView>
            <!-- crashes if I comment out this line, the problem is not caused by non-scrollable as you can add tens of Label's here -->
            <!-- <Label text="Label 1" /> -->
        </ScrollView>
    </PullRefresh:PullToRefresh>
</Page>

Crash screenshot:
screenshot_2018-01-23-15-19-06-913_org nativescri

You can reproduce the crash with other view as well, e.g., SegmentedBar (which I originally came across this issue).

Top margin issue with ios runtime 3.4.1

Check this out:

https://cl.ly/opvQ

Youll notice when I navigate to a view that has a pulltorefresh in it, the margin that is reserved normally for the spinner is shown, then adjusts. Its not pretty. If I remove the pulltorefresh, it works as expected. Thoughts?

_this.listView.refresh is not a function

Hi @bradmartin ,
For my internship I've been asked to develop a mobile application with Nativescript and Angular 2.
One of the things the app should be able to do is to get the notiffications (which I store in a listview in my app); Obviously i'd like to add the possibility to refresh the list of notifications by pulling down but even though I follow the instructions, I get this error (the one you see as the title of my post).

Here's the view :
<TabView> <StackLayout *tabItem="{title: 'Accueil'}"> </StackLayout> <StackLayout *tabItem="{title: 'Notifications'}"> <PullRefresh:PullToRefresh refresh="refreshList"> <ListView [items]="notificationsList"> <template #item="item"> <Label text="{{item.text}}" textWrap="true" id="notif" [class.boldFont]="!item.status"></Label> </template> </ListView> </PullRefresh:PullToRefresh> </StackLayout> </TabView>

and the refreshlist method I use in a Typescript file :

refreshList(args) { let pullRefresh = args.object; this._notificationService.load() .toPromise() .then(resp => { setTimeout(() => { pullRefresh.refreshing = false; }, 1000); }, err => { pullRefresh.refreshing = false; }); }

Conditionnnal blocked plugin

Hi team

I make some tests with your plugin in my vue App
it's working on IOS when I use your readme syntax

but I'm working with vuex, and when page is loading, I use a conditionnal state to show another spin indicator

and this configuration seems to blocked your refresh system

<ActivityIndicator v-if="loading" busy="true" width="100" height="100"/> <StackLayout v-else> <ScrollView orientation="horizontal"> <PullToRefresh @refresh="refreshList"> <ListView for="p in listeFiltered" class="list-group" @itemTap="showItem"> <v-template> <Label row="0" col="1" :text="p.full_name" /> </GridLayout> </v-template> </ListView> </PullToRefresh> </ScrollView> </StackLayout>

How to register element properly?

I try to import

import { registerElement } from "nativescript-angular/element-registry"; registerElement("PullToRefresh", () => require("nativescript-pulltorefresh").PullToRefresh);

inside component.ts. I got this error everytime.
ERROR Error: Content must inherit from either UIScrollView, UIWebView or WKWebView!

1__tns_run_ios_--emulator__simctl_

JS ERROR Error: Content must inherit from either UIScrollView, UIWebView or WKWebView!

hello, help me, i got same issue with #18. But, I use pulltorefresh to get data from db and check them with current data.. not for listview..

this work perfectly for Android, but not for IOS. 😢

Here my code:

my UI.xml

<page navigatedTo="onNavigatedTo"
    xmlns:PR="nativescript-pulltorefresh">

    <ActionBar title="RAN1" class="action-bar">
    </ActionBar>

    <PR:PullToRefresh refresh="onRefresh">    
        <grid-layout rows="auto,*" columns="*">
            <stack-layout col="0" row="0" class="ads" >
                <label class="tanya" text="{{ question }}" textWrap="true" />
            </stack-layout>

            <stack-layout col="0" row="1" class="content" visibility="{{ showForm ? 'visible' : 'collapsed' }}">
                <label class="label" text="Your Answer :" />
                <grid-layout rows="auto, auto" columns="*, *" visibility="{{ showEssay ? 'visible' : 'collapsed' }}">
                    <text-field row="0" colSpan="2" id="answer" />
                    <button row="1" col="1" text="Lock" tap="onLock" horizontalAlignment="right" />
                </grid-layout>

                <grid-layout rows="auto" columns="*, *" visibility="{{ showOption ? 'visible' : 'collapsed' }}">
                    <button row="0" col="0" tap="onTapA" text="{{ option_a }}" />
                    <button row="0" col="1" tap="onTapB" text="{{ option_b }}" />
                </grid-layout>
            </stack-layout>
        </grid-layout>
    </PR:PullToRefresh>
</page>

my controller.js

function onRefresh(args){
    var pullRefresh = args.object;
    statusChecker.start().then(function(bool){
        pullRefresh.refreshing = false;
        if(bool){
            condition = statusChecker.getStatusClass();
            setQuestion();
        }
        else alert("Failed. Check your connection!");
    });
}

Not working in TNS 2.5

file:///app/tns_modules/nativescript-pulltorefresh/pulltorefresh.js:65:71: JS ERROR Error: Content must inherit from UIScrollView!

Fails to build on Android for Nativescript 6.0.0

The build fails with the following error:

Exception in thread "main" java.lang.RuntimeException: Class not found android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener
        at org.nativescript.staticbindinggenerator.Generator.getClass(Generator.java:549)
        at org.nativescript.staticbindinggenerator.Generator.getInterfacesFromCache(Generator.java:532)
        at org.nativescript.staticbindinggenerator.Generator.writeBinding(Generator.java:283)
        at org.nativescript.staticbindinggenerator.Generator.generateBinding(Generator.java:171)
        at org.nativescript.staticbindinggenerator.Generator.processRows(Generator.java:234)
        at org.nativescript.staticbindinggenerator.Generator.generateBindings(Generator.java:121)
        at org.nativescript.staticbindinggenerator.Generator.writeBindings(Generator.java:97)
        at org.nativescript.staticbindinggenerator.Main.main(Main.java:50)

How to get android interface

Plugin works awesome, thank you, but I am trying get to the Android's native interface.
Any ideas what am I doing wrong?

<PullToRefresh id="pull-to-refresh" (refresh)="onPullRefresh($event)">
  ...
</PullToRefresh>
ngAfterViewInit(){

  // testing pull to refresh
  // let ptr = this.page.getViewById<View>("pull-to-refresh");
  let ptr = this.page.getViewById<ContentView>("pull-to-refresh");
  console.log('ptr', ptr)
  console.log('ptr android', ptr.android)

  // dummy to test if it works
  ptr.android.setProgressBackgroundColorSchemeColor(........)

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.