Skip to content

Commit

Permalink
Merge pull request #43 from smartface/story/AND-3725
Browse files Browse the repository at this point in the history
AND-3725
  • Loading branch information
ozcanovunc committed Oct 9, 2019
2 parents 9c5da7e + 5bb09ff commit bb7aa54
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -22,6 +22,8 @@ An extension that has following utility classes for Smartface Native Framework.
- Router (with buildExtender, page management made easy)
- Guid (creates uuid-v4 text)
- getCombinedStyle (gets style object from theme class)
- RTLTabBarController (supports Right-To-Left direction and vice versa)
- RTLSwipeView (supports Right-To-Left direction and vice versa)
- PDF (renders base64 string as pdf file in a WebView)
- RootDetection (detects if the device is rooted or not)

Expand Down
12 changes: 12 additions & 0 deletions createdoc.sh
Expand Up @@ -30,4 +30,16 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
echo "generating ./doc/${filename%%.*}.md"
npx jsdoc2md -f "./$filename" > "../../doc/router/${filename%%.*}.md"
done

pwd

cd ../components
for filename in *.js; do
if [[ "$filename" == "index.js" ]]; then
continue
fi

echo "generating ./doc/${filename%%.*}.md"
npx jsdoc2md -f "./$filename" > "../../doc/components/${filename%%.*}.md"
done
)
114 changes: 114 additions & 0 deletions doc/components/rtl-swipeview.md
@@ -0,0 +1,114 @@
<a name="module_RTLSwipeView"></a>

## RTLSwipeView : <code>object</code>
Smartface RTLSwipeView To Support RIGHT-TO-LEFT Languages

**Author**: Muhammed Yalcin Kuru <yalcin.kuru@smartface.io>
**Author**: Ozcan Ovunc <ozcan.ovunc@smartface.io>
**Copyright**: Smartface 2019

* [RTLSwipeView](#module_RTLSwipeView) : <code>object</code>
* [~RTLAndroidSwipeView](#module_RTLSwipeView..RTLAndroidSwipeView)
* [new RTLAndroidSwipeView()](#new_module_RTLSwipeView..RTLAndroidSwipeView_new)
* [~pages](#module_RTLSwipeView..pages)
* [~currentIndex](#module_RTLSwipeView..currentIndex)
* [~onPageSelected(index, page)](#module_RTLSwipeView..onPageSelected)
* [~swipeToIndex(index, animated)](#module_RTLSwipeView..swipeToIndex)
* [~onPageScrolled(index, offset)](#module_RTLSwipeView..onPageScrolled)

<a name="module_RTLSwipeView..RTLAndroidSwipeView"></a>

### RTLSwipeView~RTLAndroidSwipeView
**Kind**: inner class of [<code>RTLSwipeView</code>](#module_RTLSwipeView)
**Access**: public
**See**: [All supported arguments, properties & methods](http://ref.smartface.io/#!/api/UI.SwipeView)
<a name="new_module_RTLSwipeView..RTLAndroidSwipeView_new"></a>

#### new RTLAndroidSwipeView()
RTLSwipeView class is inherited from SwipeView. It manipulates the index/array
based functions/properties to support RTL languages. Such as, in case of app
direction is RTL, array & index values are reversed.

Note: Returned indexes or arrays won't impact the logic.

**Example**
```js
const RTLSwipeView = require("sf-extension-utils/lib/components/rtl-swipeview");

var swipeView = new RTLSwipeView({
page: currentPage,
width: 300,
maxHeight: 300,
pages: [Page1, Page2, Page3, Page4]
});

swipeView.onPageSelected = function(index, page) {
console.info(`page index ${index}`);
};
```
<a name="module_RTLSwipeView..pages"></a>

### RTLSwipeView~pages
Similar to [swipeview's pages](http://ref.smartface.io/#!/api/UI.SwipeView-property-pages). In case of
app direction is RTL, given array will be reversed then applied and then swiped last index. Otherwise as it's.

**Kind**: inner property of [<code>RTLSwipeView</code>](#module_RTLSwipeView)
**Access**: public
**Properties**

| Type |
| --- |
| <code>array</code> |

<a name="module_RTLSwipeView..currentIndex"></a>

### RTLSwipeView~currentIndex
Same as [swipeview's currentIndex](http://ref.smartface.io/#!/api/UI.SwipeView-property-currentIndex)

**Kind**: inner property of [<code>RTLSwipeView</code>](#module_RTLSwipeView)
**Access**: public
**Properties**

| Type |
| --- |
| <code>number</code> |

<a name="module_RTLSwipeView..onPageSelected"></a>

### RTLSwipeView~onPageSelected(index, page)
Same as [swipeview's onPageSelected](http://ref.smartface.io/#!/api/UI.SwipeView-event-onPageSelected)

**Kind**: inner method of [<code>RTLSwipeView</code>](#module_RTLSwipeView)
**Access**: public

| Param | Type |
| --- | --- |
| index | <code>number</code> |
| page | <code>object</code> |

<a name="module_RTLSwipeView..swipeToIndex"></a>

### RTLSwipeView~swipeToIndex(index, animated)
Same as [swipeview's swipeToIndex](http://ref.smartface.io/#!/api/UI.SwipeView-method-swipeToIndex). To swipe, pages/pageCount properties must be assigned already.

**Kind**: inner method of [<code>RTLSwipeView</code>](#module_RTLSwipeView)
**Access**: public

| Param | Type | Description |
| --- | --- | --- |
| index | <code>number</code> | Given index reversed in case of RTL. Otherwise as it is. |
| animated | <code>boolean</code> | Swipes either with animation or directly. |

<a name="module_RTLSwipeView..onPageScrolled"></a>

### RTLSwipeView~onPageScrolled(index, offset)
Same as [swipeview's onPageScrolled](http://ref.smartface.io/#!/api/UI.SwipeView-event-onPageScrolled).

**Kind**: inner method of [<code>RTLSwipeView</code>](#module_RTLSwipeView)
**Access**: public

| Param | Type |
| --- | --- |
| index | <code>number</code> |
| offset | <code>number</code> |

66 changes: 66 additions & 0 deletions doc/components/rtl-tabbarcontroller.md
@@ -0,0 +1,66 @@
<a name="module_RTLTabBarController"></a>

## RTLTabBarController : <code>object</code>
Smartface RTLTabBarController To Support RIGHT-TO-LEFT Languages

**Author**: Muhammed Yalcin Kuru <yalcin.kuru@smartface.io>
**Author**: Ozcan Ovunc <ozcan.ovunc@smartface.io>
**Copyright**: Smartface 2019

* [RTLTabBarController](#module_RTLTabBarController) : <code>object</code>
* [~RTLAndroidTabBarController](#module_RTLTabBarController..RTLAndroidTabBarController)
* [new RTLAndroidTabBarController()](#new_module_RTLTabBarController..RTLAndroidTabBarController_new)
* [~items](#module_RTLTabBarController..items)
* [~onSelected(index)](#module_RTLTabBarController..onSelected)

<a name="module_RTLTabBarController..RTLAndroidTabBarController"></a>

### RTLTabBarController~RTLAndroidTabBarController
**Kind**: inner class of [<code>RTLTabBarController</code>](#module_RTLTabBarController)
**Access**: public
**See**: [arguments, properties & methods](http://ref.smartface.io/#!/api/UI.TabBarController)
<a name="new_module_RTLTabBarController..RTLAndroidTabBarController_new"></a>

#### new RTLAndroidTabBarController()
RTLTabBarController class is inherited from TabBarController. It manipulates
the index/array based functions/properties to support RTL languages. Such as,
in case of app direction is RTL, array & index values are reversed.

Note: Returned indexes or arrays won't impact the logic.

**Example**
```js
const RTLTabBarController = require("sf-extension-utils/lib/components/rtl-tabbarcontroller");

var MyTabBarController = extend(RTLTabBarController)(
function(_super, params) {
_super(this);
this.onPageCreate = function(index) {};
}
);
```
<a name="module_RTLTabBarController..items"></a>

### RTLTabBarController~items
Similar to [tabbarcontroller's items](http://ref.smartface.io/#!/api/UI.TabBarController-property-items). Given items will be reversed then applied in case of direction is RTL.

**Kind**: inner property of [<code>RTLTabBarController</code>](#module_RTLTabBarController)
**Access**: public
**Properties**

| Name | Description |
| --- | --- |
| {@link | http://ref.smartface.io/#!/api/UI.TabBarItem TabBarItem} |

<a name="module_RTLTabBarController..onSelected"></a>

### RTLTabBarController~onSelected(index)
Same as [tabbarcontroller's onSelected](http://ref.smartface.io/#!/api/UI.TabBarController-event-onSelected).

**Kind**: inner method of [<code>RTLTabBarController</code>](#module_RTLTabBarController)
**Access**: public

| Param | Type |
| --- | --- |
| index | <code>number</code> |

159 changes: 159 additions & 0 deletions lib/components/rtl-swipeview.js
@@ -0,0 +1,159 @@
/**
* Smartface RTLSwipeView To Support RIGHT-TO-LEFT Languages
* @module RTLSwipeView
* @type {object}
* @author Muhammed Yalcin Kuru <yalcin.kuru@smartface.io>
* @author Ozcan Ovunc <ozcan.ovunc@smartface.io>
* @copyright Smartface 2019
*/

const Application = require("sf-core/application");
const extend = require("js-base/core/extend");
const SwipeView = require("sf-core/ui/swipeview");
const System = require("sf-core/device/system");

/**
* RTLSwipeView class is inherited from SwipeView. It manipulates the index/array
* based functions/properties to support RTL languages. Such as, in case of app
* direction is RTL, array & index values are reversed.
*
* Note: Returned indexes or arrays won't impact the logic.
*
* @public
* @class
* @see {@link http://ref.smartface.io/#!/api/UI.SwipeView All supported arguments, properties & methods}
* @example
* const RTLSwipeView = require("sf-extension-utils/lib/components/rtl-swipeview");
*
* var swipeView = new RTLSwipeView({
* page: currentPage,
* width: 300,
* maxHeight: 300,
* pages: [Page1, Page2, Page3, Page4]
* });
*
* swipeView.onPageSelected = function(index, page) {
* console.info(`page index ${index}`);
* };
*/

const RTLAndroidSwipeView = extend(SwipeView)(
function(_super, options = {}) {
_super(this, options);

const AndroidUnitConverter = require("sf-core/util/Android/unitconverter");

let callbackOnPageSelected,
_pages = [],
callbackOnPageScrolled;

let isRTL = () => Application.android.getLayoutDirection === Application.LayoutDirection.RIGHTTOLEFT;
let getPageLength = () => this.pageCount ? this.pageCount : this.pages.length;
let getOffsetPixels = (offsetPixels) => isRTL() ? AndroidUnitConverter.pixelToDp(this.nativeObject.getWidth()) - offsetPixels : offsetPixels;
let getIndex = (position) => isRTL() ? (getPageLength() - 1) - position : position;


Object.defineProperties(this, {
/**
* Same as {@link http://ref.smartface.io/#!/api/UI.SwipeView-event-onPageSelected swipeview's onPageSelected}
* @method
* @param {number} index
* @param {object} page
* @public
*/
"onPageSelected": {
get: () => {
return callbackOnPageSelected ?
(position, pageInstance) => {
let rPosition = getIndex(position);
callbackOnPageSelected(rPosition, this.pageInstances[position]);
} :
undefined;
},
set: (callback) => {
callbackOnPageSelected = callback;
},
enumerable: true,
configurable: true
},
/**
* Similar to {@link http://ref.smartface.io/#!/api/UI.SwipeView-property-pages swipeview's pages}. In case of
* app direction is RTL, given array will be reversed then applied and then swiped last index. Otherwise as it's.
* @property {array}
* @public
*/
"pages": {
get: function() {
return _pages;
},
set: (pages) => {
if (pages instanceof Array) {
if (pages.length < 1)
throw new TypeError("Array parameter cannot be empty.");
_pages = pages;
this.pagerAdapter.notifyDataSetChanged();
this.swipeToIndex(0, false); //Last index of swipe view
}
},
enumerable: true,
configurable: true
},
/**
* Same as {@link http://ref.smartface.io/#!/api/UI.SwipeView-property-currentIndex swipeview's currentIndex}
* @property {number}
* @public
*/
"currentIndex": {
get: () => getIndex(this.nativeObject.getCurrentItem()),
enumerable: true,
configurable: true
},
/**
* Same as {@link http://ref.smartface.io/#!/api/UI.SwipeView-method-swipeToIndex swipeview's swipeToIndex}. To swipe, pages/pageCount properties must be assigned already.
* @method
* @param {number} index - Given index reversed in case of RTL. Otherwise as it is.
* @param {boolean} animated - Swipes either with animation or directly.
* @public
*/
"swipeToIndex": {
value: (index, animated = false) => this.nativeObject.setCurrentItem(getIndex(index), animated)
},
/**
* Same as {@link http://ref.smartface.io/#!/api/UI.SwipeView-event-onPageScrolled swipeview's onPageScrolled}.
* @method
* @param {number} index
* @param {number} offset
* @public
*/
"onPageScrolled": {
get: () => {
return callbackOnPageScrolled ?
(position, offsetPixels) => {
let rPosition = getIndex(position);
//Re-look at here!
let rOffsetPixels = getOffsetPixels(offsetPixels);
callbackOnPageScrolled(rPosition, rOffsetPixels);
} :
undefined;
},
set: (callback) => {
callbackOnPageScrolled = callback;
},
enumerable: true,
configurable: true
}
});

let getPageInstanceFunc = this.getPageInstance.bind(this);
this.getPageInstance = (position) => {
let rPosition = getIndex(position);
return getPageInstanceFunc(rPosition);
};

Object.keys(options).forEach((key) => {
this[key] = options[key];
});
}
);

module.exports = System.OS === "Android" ? RTLAndroidSwipeView : SwipeView;

0 comments on commit bb7aa54

Please sign in to comment.