-
Notifications
You must be signed in to change notification settings - Fork 734
Infra/masked input to ts #1976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Infra/masked input to ts #1976
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d168396
Rename file to tsx
ethanshar 9a278e4
Migrate MaskedInput to TS and remove usaged of legacy TextField compo…
ethanshar 9770921
Create a MaskedInputMigrator
ethanshar ec7e6be
PR fixes and I changed the component to be uncontrolled because of th…
ethanshar b9c461d
Update src/components/maskedInput/new.tsx
ethanshar 4d1b090
Update src/components/maskedInput/new.tsx
ethanshar 9ee0dcd
Migrate MaskedInput screen to TS
ethanshar 6702734
Merge branch 'master' into infra/MaskedInput_toTS
ethanshar f77610c
Add pin code example to MaskedInput screen
ethanshar 5e97e17
Merge branch 'master' into infra/MaskedInput_toTS
ethanshar 1bc8436
Fix PR comments
ethanshar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import _ from 'lodash'; | ||
import React, {Component} from 'react'; | ||
import {ScrollView, StyleSheet} from 'react-native'; | ||
import {Typography, View, Text, MaskedInput, Button} from 'react-native-ui-lib'; //eslint-disable-line | ||
import {Typography, View, Text, MaskedInput, Button, Colors} from 'react-native-ui-lib'; //eslint-disable-line | ||
|
||
export default class MaskedInputScreen extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
error: '', | ||
timeValue: '15' | ||
}; | ||
} | ||
minInput = React.createRef<any>(); | ||
priceInput = React.createRef<any>(); | ||
state = { | ||
error: '', | ||
timeValue: '15' | ||
}; | ||
|
||
componentDidMount() { | ||
setTimeout(() => { | ||
this.minput.focus(); | ||
this.minInput.current.focus(); | ||
}, 500); | ||
} | ||
|
||
clearInputs = () => { | ||
this.minput.clear(); | ||
this.priceInput.clear(); | ||
this.minInput.current.clear(); | ||
this.priceInput.current.clear(); | ||
}; | ||
|
||
renderTimeText(value) { | ||
renderTimeText(value: string) { | ||
const paddedValue = _.padStart(value, 4, '0'); | ||
const hours = paddedValue.substr(0, 2); | ||
const minutes = paddedValue.substr(2, 2); | ||
|
@@ -39,7 +37,7 @@ export default class MaskedInputScreen extends Component { | |
); | ||
} | ||
|
||
renderPrice(value) { | ||
renderPrice(value: string) { | ||
const hasValue = Boolean(value && value.length > 0); | ||
return ( | ||
<View row center> | ||
|
@@ -56,6 +54,20 @@ export default class MaskedInputScreen extends Component { | |
); | ||
} | ||
|
||
renderPINCode = (value = '') => { | ||
return ( | ||
<View row centerH> | ||
{_.times(4, i => { | ||
return ( | ||
<View marginR-s3 center style={styles.pinCodeSquare}> | ||
<Text h1>{value[i]}</Text> | ||
</View> | ||
); | ||
})} | ||
</View> | ||
); | ||
}; | ||
|
||
render() { | ||
const {timeValue} = this.state; | ||
|
||
|
@@ -71,9 +83,9 @@ export default class MaskedInputScreen extends Component { | |
</Text> | ||
<MaskedInput | ||
migrate | ||
ref={r => (this.minput = r)} | ||
ref={this.minInput} | ||
renderMaskedText={this.renderTimeText} | ||
formatter={value => value?.replace(/\D/g, '')} | ||
formatter={(value: string) => value?.replace(/\D/g, '')} | ||
keyboardType={'numeric'} | ||
maxLength={4} | ||
initialValue={timeValue} | ||
|
@@ -85,11 +97,24 @@ export default class MaskedInputScreen extends Component { | |
</Text> | ||
<MaskedInput | ||
migrate | ||
ref={r => (this.priceInput = r)} | ||
ref={this.priceInput} | ||
renderMaskedText={this.renderPrice} | ||
formatter={value => value?.replace(/\D/g, '')} | ||
formatter={(value: string) => value?.replace(/\D/g, '')} | ||
keyboardType={'numeric'} | ||
/> | ||
|
||
<Text text70 marginT-s5 marginB-s4> | ||
PIN Code | ||
</Text> | ||
<MaskedInput | ||
migrate | ||
maxLength={4} | ||
ref={this.priceInput} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should create a dedicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed as well (: |
||
renderMaskedText={this.renderPINCode} | ||
formatter={(value: string) => value?.replace(/\D/g, '')} | ||
keyboardType={'numeric'} | ||
/> | ||
|
||
<View centerH marginT-100> | ||
<Button label="Clear All" onPress={this.clearInputs}/> | ||
</View> | ||
|
@@ -111,5 +136,12 @@ const styles = StyleSheet.create({ | |
header: { | ||
...Typography.text60, | ||
marginVertical: 20 | ||
}, | ||
pinCodeSquare: { | ||
width: 50, | ||
height: 70, | ||
borderWidth: 2, | ||
borderColor: Colors.grey30, | ||
borderRadius: 4 | ||
} | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixed!