Title Text

// iOS - Swift 3
class TradesViewControllerVM {
    lazy var equity: Observable<Decimal> = { /* From API & Mqtt */ }()
    lazy var account: Observable<Account> = { /* From API & Mqtt */ }()

    lazy var tradingPower: Observable<Decimal> = {
        let apiMarginUsed = self.account.map { $0.equity - $0.freeMargin }

        return Observable.combineLatest(self.equity, apiMarginUsed) { equity, marginUsed in
                return equity == Decimal(0) 
                        ? Decimal(0) 
                        : 1 - ( marginUsed / equity )
        }
    }()
}
// Android - Kotlin
class TradesActivityVM {
    val account: Observable<Account> by lazy { /* From API & Mqtt */ }
    val equity: Observable<BigDecimal> by lazy { /* From API & Mqtt */ }

    val tradingPower: Observable<BigDecimal> by lazy {
        val apiMarginUsed = account.map { it.equity - it.freeMargin }

        Observable.combineLatest(equity, apiMarginUsed) { equity, marginUsed ->
            if (equity > BigDecimal.ZERO) {
                BigDecimal.ONE - (marginUsed / equity)
            } else {
                BigDecimal.ZERO
            }
        }
    }
}
Custom Runtime WebView + Bridge Native UI Rendering + Javascript Runtime + Bridge
接近 Native Performance
使用 Native 3rd party Library
加入現有 Native Project​
// iOS - Swift 3
tradingPowerBarView.rx.ratio <- vm.tradingPower >>> disposeBag
// Android - Kotlin
tradingPowerBar.ratio() bind vm.tradingPower addTo disposeBag
Made with Slides.com