Skip to content

Conversation

@gbrvalerio
Copy link

@gbrvalerio gbrvalerio commented Oct 12, 2022

Adds support for custom segments using the new prop SegmentComponent (which is any component that complies with SegmentProps). The api remains unchanged. As a breaking change it will be better in the future if its possible to remove all references to any styling from the props and let any custom styling be handled by the SegmentComponent itself

@gbrvalerio gbrvalerio closed this Oct 12, 2022
@gbrvalerio gbrvalerio reopened this Oct 12, 2022
@gbrvalerio
Copy link
Author

example usage:

const DateTimeSegment: React.FC<SegmentProps> = ({ segment, selected }) => {
  return (
    <View style={{ justifyContent: 'center', alignItems: 'center' }}>
      <SegmentTitle selected={selected}>
        {segment === 'start-time' ? 'Start Time' : 'End Time'}
      </SegmentTitle>¼
      <SegmentTime selected={selected}>8:00 AM</SegmentTime>
    </View>
  );
};

const DateTimeSelector: React.FC<{}> = () => {
  const [currentIndex, setCurrentIndex] = useState(0);
  return (
    <>
      <InstructionText>{localization.editSchedule_selectTime}</InstructionText>
      <SegmentedControl
        containerMargin={16}
        segments={['start-time', 'end-time']}
        currentIndex={currentIndex}
        onChange={index => setCurrentIndex(index)}
        SegmentComponent={DateTimeSegment}
      />
    </>
  );
};

InstructionText, SegmentTime, SegmentTitle are styled-component components but you can get the feeling
Screen Shot 2022-10-13 at 11 50 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant