Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update data from native #134

Closed
sospartan opened this issue May 3, 2016 · 3 comments
Closed

Update data from native #134

sospartan opened this issue May 3, 2016 · 3 comments

Comments

@sospartan
Copy link
Contributor

sospartan commented May 3, 2016

Weex has an one-way data flow, from js to native. But components with 'state' will be problems, such as switch/video etc, as described in #28 .
These components' state will be update by native event, a mechanism is necessary to make changes directly to the js side. And avoiding send update event rendundantly.

For example :

<template>
  <scroller>
    <switch checked="{{switchOn}}" style="margin-bottom:20">
    </switch>
    <ui-button value="toggle switch" click="{{toggle}}"></ui-button>
  </scroller>
</template>

<script>
  module.exports = {
    data: {
      switchOn: 'true'
    },
    methods: {
      toggle: function() {
          console.log("current switch checked:"+this.switchOn);
          this.switchOn = (this.switchOn=='true'?'false':'true');
      }
    }
  };
</script>

In this case, once click the switch , the ui-button have to click twice to really toggle the switch. It's not acceptable.
I will use another fireEvent method ( https://github.com/alibaba/weex/blob/dev/src/js-framework/lib/app/ctrl.js#L112) to solve this. I'll test it in android first.

@zshshr @Jinjiang @boboning @luics @terrykingcha

@terrykingcha
Copy link
Contributor

Yes!One-way binding is not perfect. We will improve the way via some syntax sugars.

@terrykingcha terrykingcha removed this from the 0530 milestone May 4, 2016
@sospartan
Copy link
Contributor Author

sospartan commented May 4, 2016

The fireEvent syntax sugar don't fix this problem. It's just set the style and attrs of the component. JS side code is required to make these components really working.
Is there any doc about writing JS code to correspond with native module? @terrykingcha

@sospartan
Copy link
Contributor Author

I finally figure out how to make this 'one-way' thing work:

<template>
  <scroller>
    <switch checked="{{switchOn}}" style="margin-bottom:20" onchange="{{clickswitch}}">
    </switch>
    <ui-button value="toggle switch" click="{{toggle}}"></ui-button>
  </scroller>
</template>

<script>
  module.exports = {
    data: {
      switchOn: true
    },
    methods: {
    clickswitch:function(event){
      this.switchOn = event.value;
    },
      toggle: function() {
          console.log("current switch checked:"+this.switchOn);
          this.switchOn = (this.switchOn?false:true);
      }
    }
  };
</script>

There should be a more better & neat way to replace this whole onchange="{{clickswitch}}" and define method code.

sospartan added a commit that referenced this issue May 4, 2016
luics pushed a commit that referenced this issue May 16, 2016
* + [all] init

* * [android] remove the IWXRecyclerViewChild interface

* + [android] add navBarSetter interface

* * [android] bug fix of NavBar

* * [android] add weex.jks wee.txt

* * [android]  List  bugfix

* * [android] update WXComponent.java WXListComponent.java IOnLoadMoreListener.java

* * [android] update build.gradle support simple use idk

* * [ android ] fix the toast show mode : one by one mode to replace at once

* * [doc] update integrate-to-android.md

* * [android] modify switch component

* * [android] close #20

* + [android] Add WebView Component and Module

* *[test]Modify android Instrument test case util to ajust 750 width and png file

* + [android ] add navbarsetter

* +[ android ] add navigator function

* - [android] remove Deprecated api

* * [android ] modify imageRecycle Logic

* * [android] update WXcompont.java wxListComponent.java modify appear event

* + [android] text-overflow support

* Revert "Merge branch 'dev' into android"

This reverts commit 967997f, reversing
changes made to d31f74a.

* * [android] update libweexcore.so

* * [android] Refactor border draw

* * [android] ignore iml file create by intellij

* * [android] Refactor border draw

* * [android] update ScreenUtil.java modify the method of get actionbar height

* * [android] update screenUtil.java

* * [android] update WXListComponent.java

* *[android] modify playound add WEEX_TPL_KEY to Unite autotest and QR

* * [android] web tag bugfix

* * [android ] bugfix

* *[ android ] deviceType default phone

* * [android] update WXSDKInstance.java init adapter

* * [android] update wxenvironment.java modify version

* * [doc] add video src URL scheme spec

* * [Android] remove Reuse mechanism in WXListComponent

* * [android] modify scroll default Direction logic

* + [example] instance api

* +[Android] Add refresh and loadMore to "List"
- [Android] Remove reuse view mechanism of "List"

* * [Android] move refresh.we from example to test folder

* * [android] update WXListComponent.java and WXComponent.java modify appear

* * [example] fix video control problem, fix #63 .
  more detail see #134

* * [Android] Fix mis-spelling of "Refresh" tag

* * [example] close instance api example, waiting jsfm merging to dev

* * [doc] add flex-wrap spec

* * [example] add flex-wrap example

* * [Android] No textOverflow will be applied if lines=0

* * [Android] Change grade version to 2.1.0

* * [android] update WXEnvironment.java WXSDKInstance.java CaptureActivity.java dynamic replace bundle js

* * [android] update WXSDKInstance.java modify option np

* +[test] android playground add perf list with append tree testcase

* * [Android] Fix image recycle in List

* * [example] fix flex-wrap title

* * [android] update WXimage.java add new property

* * [android] update WXDomStatement.java null point

* * [example] update playground demos

* * [android] update main.js

* * [android] update WXStreamModule.java

* * [android] update wxattr.java wxrecycleimagemanager.java wximage.java

* * [android] update WXScroller.java stop load image

* * [Android] Destroy useless instance in WXEmbed when src changed

* * [doc] update doc for windows

* * [android] bug fix crash

* + [example] add new-fashion examples

* + [component] add tabbar & navbar

* * [ android ] native crash fixed #210

* + [example] add stream demo

* * [example] add `npm run build` in start script

* * [ android ]  fix list LayoutParams cast error

*  [component] update tabbar & navbar

* * [example] finish stream demo

* * [doc] update image.md add resize attribute

* * [ android ]  fix list LayoutParams cast error

* * [example] post sendHttp

* * [examples] mv params to local

* * [android] set screen h &w cache

* * [example] update text-overflow:elipssis text

* Revert "Merge branch 'dev' into android"

This reverts commit bc35bad, reversing
changes made to d5b5374.

* * [all] restore android merge to dev

* * [android] refresh android for merge branch error

* * [example] update instance api demo

* * [all] fix commit msg regex

* * [android] renew android playground

* * [android] update ImageAdapter.java remove resize

* * [android] update image-demo.we add attribute resize

* * [all] rm build from start script

* *[example] Add showcase for hyperlink("a" element)

* * [example] rename hyperlink

* * [example] add activity example entry

* * [android] update WXEnvironment.java

* * [android] update WXStreamModule.java np

* * [android] update WXSDKInstance.java rename render and add log

* *[android] update jsf 0.13.9

* * [android] so release local reference

* * [example] change href in <a> to external accessible URL

* * [example] add sub-directory supporting comment

* * [example] add dir params

* * [Android] Move flushView from renderStatement and batch to Component.bindImp(), in order to reduce the duplicate flushview when addElement to WXList.

* * [example] update image-demo.we

* * [Android] Remove recursively invoke flushView as bindImp() itself is recursive.

* * [component] fix marquee index

* * [Android] Fix RenderStatement.scrollTo() issuse in single scroller, but this fix will cause the wrong scroll offset when scroller are nested in scroller.

* * [example] panel type

* * [android] input default use single line

* * [Android] Fix scrollTo issues, this will work for single scroller and nested scroller.

* * [example] update playground

* * [android] update WXPageActivity.java modify file path

* add a todoMvc demo with some feature to be finished (#239)

* + [example] add todo mvc basic demo

* + [example] todo more fixed

* + [example] todomvc with bug

* * [example] update android assets

* * [example] need to fix todoMVC

* * [android] update build.grade

* * [example] refactor example structure

* * [Android] Fix flushview no response when image's src has been changed

* * [android] update WXInstanceWrap.java modify pro guard

* +[doc ] add list onappear and ondisappear event doc

* [example] add tabbar demo

* [example] add webview demo

* + [example] add scroller and pull-to-refresh demo (#248)

* + [example] Add appear/disappear event listener in list-basic.

* * [example] move the appear/disappear listener to cell label for Android

* + [example] add scroller-basic demo

* * [example] reindent code

* [example] add navigator demo (#250)

* * [example] update image-demo.we

* + [doc] add pull-to-refresh doc to list component

* * [doc] reference list example to examples/
sospartan pushed a commit that referenced this issue Jan 24, 2017
* * [android] update fix sticky model getComponentRect

* * [android] update module. module add method 'setModuleName'.modify module event return data formate
lybeen pushed a commit that referenced this issue Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants