Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomSlider.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2019 - 2020 Arnaud Vergnet.
  3. *
  4. * This file is part of Campus INSAT.
  5. *
  6. * Campus INSAT is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Campus INSAT is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. // @flow
  20. import * as React from 'react';
  21. import {Text, withTheme} from 'react-native-paper';
  22. import {View} from 'react-native-animatable';
  23. import Slider, {SliderProps} from '@react-native-community/slider';
  24. import type {CustomThemeType} from '../../managers/ThemeManager';
  25. type PropsType = {
  26. theme: CustomThemeType,
  27. valueSuffix?: string,
  28. ...SliderProps,
  29. };
  30. type StateType = {
  31. currentValue: number,
  32. };
  33. /**
  34. * Abstraction layer for Modalize component, using custom configuration
  35. *
  36. * @param props Props to pass to the element. Must specify an onRef prop to get an Modalize ref.
  37. * @return {*}
  38. */
  39. class CustomSlider extends React.Component<PropsType, StateType> {
  40. static defaultProps = {
  41. valueSuffix: '',
  42. };
  43. constructor(props: PropsType) {
  44. super(props);
  45. this.state = {
  46. currentValue: props.value,
  47. };
  48. }
  49. onValueChange = (value: number) => {
  50. const {props} = this;
  51. this.setState({currentValue: value});
  52. if (props.onValueChange != null) props.onValueChange(value);
  53. };
  54. render(): React.Node {
  55. const {props, state} = this;
  56. return (
  57. <View style={{flex: 1, flexDirection: 'row'}}>
  58. <Text
  59. style={{
  60. marginHorizontal: 10,
  61. marginTop: 'auto',
  62. marginBottom: 'auto',
  63. }}>
  64. {state.currentValue}min
  65. </Text>
  66. <Slider
  67. // eslint-disable-next-line react/jsx-props-no-spreading
  68. {...props}
  69. onValueChange={this.onValueChange}
  70. />
  71. </View>
  72. );
  73. }
  74. }
  75. export default withTheme(CustomSlider);