Skip to content

fix: update theme stylesheet access pattern #2573

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielbogomazov
Copy link

@danielbogomazov danielbogomazov commented Dec 11, 2024

Fixes #2336

This PR replaces bracket notation for theme access with optional chaining to align with the Theme interface style.

Motivation

The current implementation has a discrepancy between the Theme interface defined in TypeScript versus the JavaScript styling logic. This can lead to a poor developer experience, as the interface should serve as a guide for interacting with the library. The following examples illustrate the need for this change.

Example 1: Conforms to the Theme Interface but Does Not Apply the Custom Styling

In this example, the code adheres to the Theme interface, but the JavaScript does not apply the theme's styling correctly.

import { Calendar } from 'react-native-calendars';
import { Theme } from 'react-native-calendars/src/types';

export default function Foo() {
  const theme: Theme = {
    stylesheet: {
      calendar: {
        header: {
          monthText: {
            color: 'red',
          },
        },
      },
    },
  };

  return <Calendar theme={theme} />;
}
Screenshot 2024-12-11 at 12 22 44 AM

Example 2: Applies Custom Styles but Does Not Conform to the Theme Interface

In this case, custom styles are applied, but the implementation does not conform to the Theme interface, leading to TypeScript complaints.

import { Calendar } from 'react-native-calendars';
import { Theme } from 'react-native-calendars/src/types';

export default function Foo() {
  const theme: Theme = {
    'stylesheet.calendar.header': {
      monthText: {
        color: 'red',
      },
    },
  };

  return <Calendar theme={theme} />;
}
Screenshot 2024-12-11 at 12 21 31 AM Screenshot 2024-12-11 at 12 14 14 AM

Replace bracket notation theme access with optional
chaining to match the style of the `Theme` interface.
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.

[Calendar] [theme] Calendar theme stylesheet customization isn't working as expected
1 participant