From 6038040f8e8238fc7fae943aa623d6f32693d4f1 Mon Sep 17 00:00:00 2001 From: Felix Oghina Date: Thu, 7 Apr 2016 18:08:29 -0700 Subject: [PATCH] expose pageMargin prop on ViewPagerAndroid Reviewed By: sahrens Differential Revision: D3145366 fb-gh-sync-id: 6412d51a698b2c932c915e405e4bbc35e96060dc fbshipit-source-id: 6412d51a698b2c932c915e405e4bbc35e96060dc --- .../ViewPagerAndroidExample.android.js | 8 ++++++++ .../ViewPager/ViewPagerAndroid.android.js | 16 +++++++++++++--- .../views/viewpager/ReactViewPagerManager.java | 7 +++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Examples/UIExplorer/ViewPagerAndroidExample.android.js b/Examples/UIExplorer/ViewPagerAndroidExample.android.js index 0e672ee8c..d2b1464ee 100644 --- a/Examples/UIExplorer/ViewPagerAndroidExample.android.js +++ b/Examples/UIExplorer/ViewPagerAndroidExample.android.js @@ -1,4 +1,11 @@ /** + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * * The examples provided by Facebook are for non-commercial testing and * evaluation purposes only. * @@ -162,6 +169,7 @@ var ViewPagerAndroidExample = React.createClass({ onPageScroll={this.onPageScroll} onPageSelected={this.onPageSelected} onPageScrollStateChanged={this.onPageScrollStateChanged} + pageMargin={10} ref={viewPager => { this.viewPager = viewPager; }}> {pages} diff --git a/Libraries/Components/ViewPager/ViewPagerAndroid.android.js b/Libraries/Components/ViewPager/ViewPagerAndroid.android.js index a8af44974..03dc90211 100644 --- a/Libraries/Components/ViewPager/ViewPagerAndroid.android.js +++ b/Libraries/Components/ViewPager/ViewPagerAndroid.android.js @@ -1,15 +1,18 @@ /** - * Copyright 2004-present Facebook. All Rights Reserved. + * Copyright (c) 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. * * @providesModule ViewPagerAndroid * @flow */ 'use strict'; -var NativeMethodsMixin = require('NativeMethodsMixin'); var React = require('React'); var ReactElement = require('ReactElement'); -var ReactNativeViewAttributes = require('ReactNativeViewAttributes'); var ReactPropTypes = require('ReactPropTypes'); var UIManager = require('UIManager'); var View = require('View'); @@ -104,6 +107,12 @@ var ViewPagerAndroid = React.createClass({ */ onPageSelected: ReactPropTypes.func, + /** + * Blank space to show between pages. This is only visible while scrolling, pages are still + * edge-to-edge. + */ + pageMargin: ReactPropTypes.number, + /** * Determines whether the keyboard gets dismissed in response to a drag. * - 'none' (the default), drags do not dismiss the keyboard. @@ -204,6 +213,7 @@ var ViewPagerAndroid = React.createClass({ render: function() { return ( { public void removeViewAt(ReactViewPager parent, int index) { parent.removeViewFromAdapter(index); } + + @ReactProp(name = "pageMargin", defaultFloat = 0) + public void setPageMargin(ReactViewPager pager, float margin) { + pager.setPageMargin((int) PixelUtil.toPixelFromDIP(margin)); + } }