From 76acabff5194b705ab94daa51ca0d647e1206977 Mon Sep 17 00:00:00 2001 From: Mehdi Al Ouafi Date: Tue, 2 Oct 2018 13:32:13 +0200 Subject: [PATCH] convert all custom function, see #12 in main repo --- .../setCustomActivityIndicator.js | 24 ++-- src/CustomFunctions/setCustomImage.js | 26 ++--- .../setCustomKeyboardAvoidingView.js | 24 ++-- src/CustomFunctions/setCustomListView.js | 26 ++--- src/CustomFunctions/setCustomModal.js | 26 ++--- src/CustomFunctions/setCustomPicker.js | 26 ++--- .../setCustomRefreshControl.js | 26 ++--- src/CustomFunctions/setCustomScrollView.js | 26 ++--- src/CustomFunctions/setCustomSlider.js | 26 ++--- src/CustomFunctions/setCustomStatusBar.js | 26 ++--- src/CustomFunctions/setCustomSwitch.js | 26 ++--- src/CustomFunctions/setCustomText.js | 26 ++--- src/CustomFunctions/setCustomTextInput.js | 26 ++--- src/CustomFunctions/setCustomTouchable.js | 103 +++++++++--------- src/CustomFunctions/setCustomView.js | 22 ++-- src/CustomFunctions/setCustomWebView.js | 22 ++-- 16 files changed, 228 insertions(+), 253 deletions(-) diff --git a/src/CustomFunctions/setCustomActivityIndicator.js b/src/CustomFunctions/setCustomActivityIndicator.js index e4458fa..51b8306 100644 --- a/src/CustomFunctions/setCustomActivityIndicator.js +++ b/src/CustomFunctions/setCustomActivityIndicator.js @@ -1,19 +1,19 @@ -import { ActivityIndicator } from 'react-native'; +import { ActivityIndicator } from 'react-native' export const setCustomActivityIndicator = customProps => { - const ActivityIndicatorRender = ActivityIndicator.prototype.render; - const initialDefaultProps = ActivityIndicator.prototype.constructor.defaultProps; - ActivityIndicator.prototype.constructor.defaultProps = { + const ActivityIndicatorRender = ActivityIndicator.render + const initialDefaultProps = ActivityIndicator.defaultProps + ActivityIndicator.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - ActivityIndicator.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + ActivityIndicator.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return ActivityIndicatorRender.apply(this, arguments); + return ActivityIndicatorRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomImage.js b/src/CustomFunctions/setCustomImage.js index 602a4a7..5b36ccf 100644 --- a/src/CustomFunctions/setCustomImage.js +++ b/src/CustomFunctions/setCustomImage.js @@ -1,21 +1,19 @@ -import { - Image -} from 'react-native'; +import { Image } from 'react-native' export const setCustomImage = customProps => { - const ImageRender = Image.prototype.render; - const initialDefaultProps = Image.prototype.constructor.defaultProps; - Image.prototype.constructor.defaultProps = { + const ImageRender = Image.render + const initialDefaultProps = Image.defaultProps + Image.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - Image.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + Image.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return ImageRender.apply(this, arguments); + return ImageRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomKeyboardAvoidingView.js b/src/CustomFunctions/setCustomKeyboardAvoidingView.js index cfb8904..21d7333 100644 --- a/src/CustomFunctions/setCustomKeyboardAvoidingView.js +++ b/src/CustomFunctions/setCustomKeyboardAvoidingView.js @@ -1,19 +1,19 @@ -import { KeyboardAvoidingView } from 'react-native'; +import { KeyboardAvoidingView } from 'react-native' export const setCustomKeyboardAvoidingView = customProps => { - const KeyboardAvoidingViewRender = KeyboardAvoidingView.prototype.render; - const initialDefaultProps = KeyboardAvoidingView.prototype.constructor.defaultProps; - KeyboardAvoidingView.prototype.constructor.defaultProps = { + const KeyboardAvoidingViewRender = KeyboardAvoidingView.render + const initialDefaultProps = KeyboardAvoidingView.defaultProps + KeyboardAvoidingView.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - KeyboardAvoidingView.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + KeyboardAvoidingView.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return KeyboardAvoidingViewRender.apply(this, arguments); + return KeyboardAvoidingViewRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomListView.js b/src/CustomFunctions/setCustomListView.js index 8fb74b6..895e2bc 100644 --- a/src/CustomFunctions/setCustomListView.js +++ b/src/CustomFunctions/setCustomListView.js @@ -1,21 +1,19 @@ -import { - ListView -} from 'react-native'; +import { ListView } from 'react-native' export const setCustomListView = customProps => { - const ListViewRender = ListView.prototype.render; - const initialDefaultProps = ListView.prototype.constructor.defaultProps; - ListView.prototype.constructor.defaultProps = { + const ListViewRender = ListView.render + const initialDefaultProps = ListView.defaultProps + ListView.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - ListView.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + ListView.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return ListViewRender.apply(this, arguments); + return ListViewRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomModal.js b/src/CustomFunctions/setCustomModal.js index b1ba5ad..b63edae 100644 --- a/src/CustomFunctions/setCustomModal.js +++ b/src/CustomFunctions/setCustomModal.js @@ -1,21 +1,19 @@ -import { - Modal -} from 'react-native'; +import { Modal } from 'react-native' export const setCustomModal = customProps => { - const ModalRender = Modal.prototype.render; - const initialDefaultProps = Modal.prototype.constructor.defaultProps; - Modal.prototype.constructor.defaultProps = { + const ModalRender = Modal.render + const initialDefaultProps = Modal.defaultProps + Modal.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - Modal.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + Modal.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return ModalRender.apply(this, arguments); + return ModalRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomPicker.js b/src/CustomFunctions/setCustomPicker.js index 5106363..2285cb9 100644 --- a/src/CustomFunctions/setCustomPicker.js +++ b/src/CustomFunctions/setCustomPicker.js @@ -1,21 +1,19 @@ -import { - Picker -} from 'react-native'; +import { Picker } from 'react-native' export const setCustomPicker = customProps => { - const PickerRender = Picker.prototype.render; - const initialDefaultProps = Picker.prototype.constructor.defaultProps; - Picker.prototype.constructor.defaultProps = { + const PickerRender = Picker.render + const initialDefaultProps = Picker.defaultProps + Picker.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - Picker.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + Picker.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return PickerRender.apply(this, arguments); + return PickerRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomRefreshControl.js b/src/CustomFunctions/setCustomRefreshControl.js index b5164d5..7a341bf 100644 --- a/src/CustomFunctions/setCustomRefreshControl.js +++ b/src/CustomFunctions/setCustomRefreshControl.js @@ -1,21 +1,19 @@ -import { - RefreshControl -} from 'react-native'; +import { RefreshControl } from 'react-native' export const setCustomRefreshControl = customProps => { - const RefreshControlRender = RefreshControl.prototype.render; - const initialDefaultProps = RefreshControl.prototype.constructor.defaultProps; - RefreshControl.prototype.constructor.defaultProps = { + const RefreshControlRender = RefreshControl.render + const initialDefaultProps = RefreshControl.defaultProps + RefreshControl.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - RefreshControl.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + RefreshControl.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return RefreshControlRender.apply(this, arguments); + return RefreshControlRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomScrollView.js b/src/CustomFunctions/setCustomScrollView.js index ef2333d..b0ca8fe 100644 --- a/src/CustomFunctions/setCustomScrollView.js +++ b/src/CustomFunctions/setCustomScrollView.js @@ -1,21 +1,19 @@ -import { - ScrollView -} from 'react-native'; +import { ScrollView } from 'react-native' export const setCustomScrollView = customProps => { - const ScrollViewRender = ScrollView.prototype.render; - const initialDefaultProps = ScrollView.prototype.constructor.defaultProps; - ScrollView.prototype.constructor.defaultProps = { + const ScrollViewRender = ScrollView.render + const initialDefaultProps = ScrollView.defaultProps + ScrollView.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - ScrollView.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + ScrollView.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return ScrollViewRender.apply(this, arguments); + return ScrollViewRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomSlider.js b/src/CustomFunctions/setCustomSlider.js index 3c22914..b054c22 100644 --- a/src/CustomFunctions/setCustomSlider.js +++ b/src/CustomFunctions/setCustomSlider.js @@ -1,21 +1,19 @@ -import { - Slider -} from 'react-native'; +import { Slider } from 'react-native' export const setCustomSlider = customProps => { - const SliderRender = Slider.prototype.render; - const initialDefaultProps = Slider.prototype.constructor.defaultProps; - Slider.prototype.constructor.defaultProps = { + const SliderRender = Slider.render + const initialDefaultProps = Slider.defaultProps + Slider.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - Slider.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + Slider.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return SliderRender.apply(this, arguments); + return SliderRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomStatusBar.js b/src/CustomFunctions/setCustomStatusBar.js index 0c6fb64..554dda8 100644 --- a/src/CustomFunctions/setCustomStatusBar.js +++ b/src/CustomFunctions/setCustomStatusBar.js @@ -1,21 +1,19 @@ -import { - StatusBar -} from 'react-native'; +import { StatusBar } from 'react-native' export const setCustomStatusBar = customProps => { - const StatusBarRender = StatusBar.prototype.render; - const initialDefaultProps = StatusBar.prototype.constructor.defaultProps; - StatusBar.prototype.constructor.defaultProps = { + const StatusBarRender = StatusBar.render + const initialDefaultProps = StatusBar.defaultProps + StatusBar.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - StatusBar.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + StatusBar.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return StatusBarRender.apply(this, arguments); + return StatusBarRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomSwitch.js b/src/CustomFunctions/setCustomSwitch.js index cd6cd48..29515d3 100644 --- a/src/CustomFunctions/setCustomSwitch.js +++ b/src/CustomFunctions/setCustomSwitch.js @@ -1,21 +1,19 @@ -import { - Switch -} from 'react-native'; +import { Switch } from 'react-native' export const setCustomSwitch = customProps => { - const SwitchRender = Switch.prototype.render; - const initialDefaultProps = Switch.prototype.constructor.defaultProps; - Switch.prototype.constructor.defaultProps = { + const SwitchRender = Switch.render + const initialDefaultProps = Switch.defaultProps + Switch.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - Switch.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + Switch.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return SwitchRender.apply(this, arguments); + return SwitchRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomText.js b/src/CustomFunctions/setCustomText.js index ce717c6..7f0902b 100644 --- a/src/CustomFunctions/setCustomText.js +++ b/src/CustomFunctions/setCustomText.js @@ -1,21 +1,19 @@ -import { - Text, -} from 'react-native'; +import { Text } from 'react-native' export const setCustomText = customProps => { - const TextRender = Text.prototype.render; - const initialDefaultProps = Text.prototype.constructor.defaultProps; - Text.prototype.constructor.defaultProps = { + const TextRender = Text.render + const initialDefaultProps = Text.defaultProps + Text.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - Text.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + Text.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return TextRender.apply(this, arguments); + return TextRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomTextInput.js b/src/CustomFunctions/setCustomTextInput.js index bd430b3..6757ba7 100644 --- a/src/CustomFunctions/setCustomTextInput.js +++ b/src/CustomFunctions/setCustomTextInput.js @@ -1,21 +1,19 @@ -import { - TextInput -} from 'react-native'; +import { TextInput } from 'react-native' export const setCustomTextInput = customProps => { - const TextInputRender = TextInput.prototype.render; - const initialDefaultProps = TextInput.prototype.constructor.defaultProps; - TextInput.prototype.constructor.defaultProps = { + const TextInputRender = TextInput.render + const initialDefaultProps = TextInput.defaultProps + TextInput.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - TextInput.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + TextInput.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return TextInputRender.apply(this, arguments); + return TextInputRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomTouchable.js b/src/CustomFunctions/setCustomTouchable.js index 81a5f9c..daed390 100644 --- a/src/CustomFunctions/setCustomTouchable.js +++ b/src/CustomFunctions/setCustomTouchable.js @@ -5,74 +5,71 @@ import { TouchableOpacity } from 'react-native'; -export const setCustomTouchableHighlight = customProps => { - const TouchableHighlightRender = TouchableHighlight.prototype.render; - const initialDefaultProps = TouchableHighlight.prototype.constructor.defaultProps; - TouchableHighlight.prototype.constructor.defaultProps = { - ...initialDefaultProps, - ...customProps, - } - TouchableHighlight.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; - try { - return TouchableHighlightRender.apply(this, arguments); - } finally { - this.props = oldProps; - } - }; -}; - export const setCustomTouchableNativeFeedback = customProps => { - const TouchableNativeFeedbackRender = TouchableNativeFeedback.prototype.render; - const initialDefaultProps = TouchableNativeFeedback.prototype.constructor.defaultProps; - TouchableNativeFeedback.prototype.constructor.defaultProps = { + const TouchableNativeFeedbackRender = TouchableNativeFeedback.render + const initialDefaultProps = TouchableNativeFeedback.defaultProps + TouchableNativeFeedback.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - TouchableNativeFeedback.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + TouchableNativeFeedback.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return TouchableNativeFeedbackRender.apply(this, arguments); + return TouchableNativeFeedbackRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; - + } +} export const setCustomTouchableWithoutFeedback = customProps => { - const TouchableWithoutFeedbackRender = TouchableWithoutFeedback.prototype.render; - const initialDefaultProps = TouchableWithoutFeedback.prototype.constructor.defaultProps; - TouchableWithoutFeedback.prototype.constructor.defaultProps = { + const TouchableWithoutFeedbackRender = TouchableWithoutFeedback.render + const initialDefaultProps = TouchableWithoutFeedback.defaultProps + TouchableWithoutFeedback.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - TouchableWithoutFeedback.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + TouchableWithoutFeedback.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return TouchableWithoutFeedbackRender.apply(this, arguments); + return TouchableWithoutFeedbackRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; - + } +} export const setCustomTouchableOpacity = customProps => { - const TouchableOpacityRender = TouchableOpacity.prototype.render; - const initialDefaultProps = TouchableOpacity.prototype.constructor.defaultProps; - TouchableOpacity.prototype.constructor.defaultProps = { + const TouchableOpacityRender = TouchableOpacity.render + const initialDefaultProps = TouchableOpacity.defaultProps + TouchableOpacity.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - TouchableOpacity.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + TouchableOpacity.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return TouchableOpacityRender.apply(this, arguments); + return TouchableOpacityRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} +export const setCustomTouchableHighlight = customProps => { + const TouchableHighlightRender = TouchableHighlight.render + const initialDefaultProps = TouchableHighlight.defaultProps + TouchableHighlight.defaultProps = { + ...initialDefaultProps, + ...customProps + } + TouchableHighlight.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } + try { + return TouchableHighlightRender.apply(this, arguments) + } finally { + props = oldProps + } + } +} diff --git a/src/CustomFunctions/setCustomView.js b/src/CustomFunctions/setCustomView.js index a9c50a6..c88734d 100644 --- a/src/CustomFunctions/setCustomView.js +++ b/src/CustomFunctions/setCustomView.js @@ -3,19 +3,19 @@ import { } from 'react-native'; export const setCustomView = customProps => { - const ViewRender = View.prototype.render; - const initialDefaultProps = View.prototype.constructor.defaultProps; - View.prototype.constructor.defaultProps = { + const ViewRender = View.render + const initialDefaultProps = View.defaultProps + View.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - View.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + View.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return ViewRender.apply(this, arguments); + return ViewRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +} diff --git a/src/CustomFunctions/setCustomWebView.js b/src/CustomFunctions/setCustomWebView.js index c38e763..687dc95 100644 --- a/src/CustomFunctions/setCustomWebView.js +++ b/src/CustomFunctions/setCustomWebView.js @@ -3,19 +3,19 @@ import { } from 'react-native'; export const setCustomWebView = customProps => { - const WebViewRender = WebView.prototype.render; - const initialDefaultProps = WebView.prototype.constructor.defaultProps; - WebView.prototype.constructor.defaultProps = { + const WebViewRender = WebView.render + const initialDefaultProps = WebView.defaultProps + WebView.defaultProps = { ...initialDefaultProps, - ...customProps, + ...customProps } - WebView.prototype.render = function render() { - let oldProps = this.props; - this.props = { ...this.props, style: [customProps.style, this.props.style] }; + WebView.render = function render(props) { + let oldProps = props + props = { ...props, style: [customProps.style, props.style] } try { - return WebViewRender.apply(this, arguments); + return WebViewRender.apply(this, arguments) } finally { - this.props = oldProps; + props = oldProps } - }; -}; + } +}