Skip to content

Commit

Permalink
feat: Replace old legacy ref string by the new callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamilquery committed Oct 19, 2017
1 parent c0aaf71 commit 8420a80
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 8 deletions.
58 changes: 58 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"extends": [
"airbnb",
"plugin:flowtype/recommended",
],
"plugins": [
"flowtype"
],
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"allowImportExportEverywhere": false,
"codeFrame": false
},
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true,
"jest": true
},
"rules": {
"class-methods-use-this": [ 0, {
"exceptMethods": []
}],

"react/jsx-filename-extension": [ 1, {
"extensions": [".js", ".jsx"]
}],
"react/jsx-max-props-per-line": [ 1, {
"maximum": 2,
"when": "multiline"
}],
"react/prefer-stateless-function": [ 0, {} ],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}],
"react/sort-comp": [ 2, {
order: [
"type-annotations",
"static-methods",
"life-cycle",
"everything-else",
"render"
]
}],
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": true,
"requireReturnDescription": true
}]
}
}
53 changes: 53 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/
.*/node_modules/.*

; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*

; .*/node_modules/expo/.*

; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo is inside the root
.*/Libraries/react-native/React.js
.*/Libraries/react-native/ReactNative.js

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/
./flow-typed/

[options]
emoji=true

module.system=haste

esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FixMe
suppress_type=$FlowExpectedError

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-7]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

unsafe.enable_getters_and_setters=true

[version]
^0.52.0
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ export default class MyComponent extends Component {
// isValid method returns if the inputed value is valid.
// Ex: if you input 40/02/1990 30:20:20, it will return false
// because in this case, the day and the hour is invalid.
let valid = this.refs['myDateText'].isValid();
let valid = this.myDateText.isValid();

// get converted value. Using type=datetime, it returns the moment object.
// If it's using type=money, it returns a Number object.
let rawValue = this.refs['myDateText'].getRawValue();
let rawValue = this.myDateText.getRawValue();
}

render() {
// the type is required but options is required only for some specific types.
return (
<TextInputMask
ref={'myDateText'}
refInput={(ref) => this.myDateText = ref;}
type={'datetime'}
options={{
format: 'DD-MM-YYYY HH:mm:ss'
Expand Down Expand Up @@ -113,7 +113,7 @@ const Textfield = MKTextField.textfield()


<TextInputMask
ref={'myDateText'}
refInput={(ref) => this.myDateText = ref;}
type={'money'}
style={styles.input}
customTextInput={Textfield}
Expand Down Expand Up @@ -144,7 +144,7 @@ export default class App extends React.Component {
return (
<View style={styles.container}>
<TextInputMask
ref={'myDateText'}
refInput={(ref) => this.myDateText = ref;}
// here we set the custom component and their props.
customTextInput={Kaede}
customTextInputProps={{
Expand Down
13 changes: 10 additions & 3 deletions lib/text-input-mask.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
// @flow
import React from 'react';
import {
StyleSheet,
TextInput
TextInput,
} from 'react-native';
import BaseTextComponent from './base-text-component';

Expand Down Expand Up @@ -50,7 +51,13 @@ export default class TextInputMask extends BaseTextComponent {

return (
<Input
ref={INPUT_TEXT_REF}
ref={(ref) => {
if(ref) {
if (typeof this.props.refInput === 'function') {
this.props.refInput(ref);
}
}
}}
keyboardType={this._getKeyboardType()}
{...this.props}
{...customTextInputProps}
Expand Down

0 comments on commit 8420a80

Please sign in to comment.