Skip to content

Fix updating both styles at once on iOS#269

Merged
tomekzaw merged 1 commit intomainfrom
@tomekzaw/fix-style-change
Apr 8, 2024
Merged

Fix updating both styles at once on iOS#269
tomekzaw merged 1 commit intomainfrom
@tomekzaw/fix-style-change

Conversation

@tomekzaw
Copy link
Copy Markdown
Collaborator

@tomekzaw tomekzaw commented Apr 8, 2024

Details

This PR fixes the formatting of MarkdownTextInput when both style and markdownStyle are changed in a single React render on iOS.

Before After
before.mp4
after.mp4

Related Issues

Expensify/App#39348

Manual Tests

App.tsx
import * as React from 'react';

import {Button, StyleSheet, Text, View} from 'react-native';

import {MarkdownTextInput} from '@expensify/react-native-live-markdown';

export default function App() {
  const [value, setValue] = React.useState('Hello *world* `inline code`');
  const [state1, setState1] = React.useState(false);
  const [state2, setState2] = React.useState(false);

  const textColor = state1 ? 'lime' : 'green';
  const codeColor = state2 ? 'cyan' : 'blue';

  return (
    <View style={styles.container}>
      <Text>text color: {textColor}</Text>
      <Text>code color color: {codeColor}</Text>
      <MarkdownTextInput
        multiline
        value={value}
        onChangeText={setValue}
        style={[styles.input, {color: textColor}]}
        markdownStyle={{code: {color: codeColor}}}
      />
      <Button
        title="Toggle text color"
        onPress={() => setState1((s) => !s)}
      />
      <Button
        title="Toggle code color"
        onPress={() => setState2((s) => !s)}
      />
      <Button
        title="Toggle both"
        onPress={() => {
          setState1((s) => !s);
          setState2((s) => !s);
        }}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    marginTop: 60,
  },
  input: {
    fontSize: 20,
    width: 300,
    padding: 5,
    borderColor: 'gray',
    borderWidth: 1,
    textAlignVertical: 'top',
  },
});

Linked PRs

@tomekzaw tomekzaw requested a review from robertKozik April 8, 2024 21:35
Copy link
Copy Markdown
Contributor

@robertKozik robertKozik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

2 participants