Giter Club home page Giter Club logo

Comments (18)

ATShiTou avatar ATShiTou commented on June 9, 2024

你在什么时候调用endLoading,什么时候就开始回弹。自己掌握时间

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

你在什么时候调用endLoading,什么时候就开始回弹。自己掌握时间

onRefresh={this._onRefresh}

_onRefresh = () => {
setTimeout(() => {
// this.setState({

        // })
        this._scrollView.endRefresh();
    }, 2000);
};

endLoading ?

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

你在什么时候调用endLoading,什么时候就开始回弹。自己掌握时间

`_onRefresh = () => {

    setTimeout(() => {
        // this.setState({
            
        // })
        this._scrollView.endRefresh();
    },5000);
};

_onLoading = () => {
    setTimeout(() => {
        this._scrollView.endLoading()
    }, 2000);
}`

是这样?,我还是不会

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

你在什么时候调用endLoading,什么时候就开始回弹。自己掌握时间

老大,我说的是下拉刷新,refreshHeader是我自定义的

from react-native-spring-scrollview.

ATShiTou avatar ATShiTou commented on June 9, 2024

是一样的,你调用endRefresh函数就开始回弹,这个你自己控制啊。

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

是一样的,你调用endRefresh函数就开始回弹,这个你自己控制啊。

我的意思是最后一个状态显示的文字 结束刷新一出来就立马回弹了,都没来得及看,这能控制,最后一个状态文字 结束刷新停留个2秒后,然后再回弹?

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

是一样的,你调用endRefresh函数就开始回弹,这个你自己控制啊。

onRefresh={()=>{
setTimeout(()=>{
this._scrollView.endRefresh();
},2000);
}}
我这样写,最后一个状态文字刷新完成一出现立马回弹了,如果字数多点,就看不出写的什么

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

我想了一天了,确实实现不了我的需求

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

onRefresh={()=>{
setTimeout(()=>{
this._scrollView.endLoading(); // endLoading不会结束refreshing状态,无效
// this._scrollView.endRefresh(); //此处调用立马变成rebound状态同时回弹,不能控制停留
},1000);
}}
refreshHeader={SimpleRefreshHeader}

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

我的需求就是 使用demo里的NormalHeader,怎么做到最后一个状态Refresh completed文字能停留2秒

from react-native-spring-scrollview.

ATShiTou avatar ATShiTou commented on June 9, 2024

没有提供这种功能定制化,你要实现可以fork去自己改:

iOS: STSpringScrollView.m

- (void)endRefresh {
    if ([self hitRefreshStatus:@[@"refreshing"]]) {
        self.refreshStatus = @"rebound";
        [self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0) animated:YES];
    }
}

- (void)endLoading {
    if ([self hitLoadingStatus:@[@"loading"]]) {
        self.loadingStatus = @"rebound";
        [self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentSize.height-self.bounds.size.height) animated:YES];
    }
}

安卓:SpringScrollView.java

    public void endRefresh() {
        if (!refreshStatus.equals("refreshing")) return;
        refreshStatus = "rebound";
        if (verticalAnimation != null) verticalAnimation.cancel();
        contentInsets.top = 0;
        verticalAnimation = new DecelerateAnimation(contentOffset.y, 0, 500) {
            @Override
            protected void onUpdate(float value) {
                setContentOffset(contentOffset.x, value);
            }
        };
        verticalAnimation.start();
    }

    public void endLoading() {
        if (!loadingStatus.equals("loading")) return;
        loadingStatus = "rebound";
        if (verticalAnimation != null) verticalAnimation.cancel();
        contentInsets.bottom = 0;
        verticalAnimation = new DecelerateAnimation(contentOffset.y, contentSize.height - size.height, 500) {
            @Override
            protected void onUpdate(float value) {
                setContentOffset(contentOffset.x, value);
            }
        };
        verticalAnimation.start();
    }

要先发送状态改变事件,定时2秒后再调用对应的动画回弹:
安卓发送事件是:sendOnScrollEvent
iOS是

- (void)sendScrollEventWithName:(NSString *)eventName
                     scrollView:(UIScrollView *)scrollView
                       userData:(NSDictionary *)userData{
    NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:userData];
    [data setObject:self.refreshStatus forKey:@"refreshStatus"];
    [data setObject:self.loadingStatus forKey:@"loadingStatus"];
    [super sendScrollEventWithName:eventName scrollView:scrollView userData:data];
}

from react-native-spring-scrollview.

ATShiTou avatar ATShiTou commented on June 9, 2024

还有要注意的是,发送事件在某些特定情况下收不到。这个是RN一直以来的bug,很多做自定义下拉刷新的人都遇到过。我采取的策略是在滑动的时候一直把当前状态往js发,丢失一两次事件无所谓。反正滑动会发很多事件。

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

还有要注意的是,发送事件在某些特定情况下收不到。这个是RN一直以来的bug,很多做自定义下拉刷新的人都遇到过。我采取的策略是在滑动的时候一直把当前状态往js发,丢失一两次事件无所谓。反正滑动会发很多事件。

暂时没有原生能力修改,,,挺遗憾了

from react-native-spring-scrollview.

ATShiTou avatar ATShiTou commented on June 9, 2024

其实你也不用这样修改代码,一些折中的方法也是可行的。你要是能够在刷新完成以后给你的自定义SimpleRefreshHeader 发送消息,让你的SimpleRefreshHeader 显示成“刷新完成”的状态,然后在两秒后再调用endRefresh也是可行的。

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

其实你也不用这样修改代码,一些折中的方法也是可行的。你要是能够在刷新完成以后给你的自定义SimpleRefreshHeader 发送消息,让你的SimpleRefreshHeader 显示成“刷新完成”的状态,然后在两秒后再调用endRefresh也是可行的。

我试试,听着好像行

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

其实你也不用这样修改代码,一些折中的方法也是可行的。你要是能够在刷新完成以后给你的自定义SimpleRefreshHeader 发送消息,让你的SimpleRefreshHeader 显示成“刷新完成”的状态,然后在两秒后再调用endRefresh也是可行的。

好像不对,我下拉松手后一直是refreshing 状态,我没办法刷新完成以后给我的自定义SimpleRefreshHeader 发送消息,这一部我只能发endRefrsh,但是我一写endRefresh就立马结束。
因为这个状态refreshing - rebound ,中间没有什么可以控制了,只能endRefresh来控制

from react-native-spring-scrollview.

ATShiTou avatar ATShiTou commented on June 9, 2024

可以考虑发送全局消息,这是折中办法。这样不用修改源码,不然的话需要需改
SpringScrollView.js:

_renderRefreshHeader() {
    const { onRefresh, refreshHeader: Refresh } = this.props;
    const measured = this._height !== undefined && this._contentHeight !== undefined;
    if (!measured) return null;
    return (
      onRefresh && (
        <Animated.View style={this._getRefreshHeaderStyle()}>
          <Refresh
            ref={ref => (this._refreshHeader = ref)}
            offset={this._offsetY}
            maxHeight={Refresh.height}
          />
        </Animated.View>
      )
    );
  }

或者加一个方法调用this._refreshHeader.onMessage ,方法很多。

from react-native-spring-scrollview.

wowtrxqn avatar wowtrxqn commented on June 9, 2024

可以考虑发送全局消息,这是折中办法。这样不用修改源码,不然的话需要需改
SpringScrollView.js:

_renderRefreshHeader() {
    const { onRefresh, refreshHeader: Refresh } = this.props;
    const measured = this._height !== undefined && this._contentHeight !== undefined;
    if (!measured) return null;
    return (
      onRefresh && (
        <Animated.View style={this._getRefreshHeaderStyle()}>
          <Refresh
            ref={ref => (this._refreshHeader = ref)}
            offset={this._offsetY}
            maxHeight={Refresh.height}
          />
        </Animated.View>
      )
    );
  }

或者加一个方法调用this._refreshHeader.onMessage ,方法很多。

QQ图片20190921173117
我这样已经实现了我要的效果了,就是不知道有没有其他性能什么的问题

from react-native-spring-scrollview.

Related Issues (20)

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.