Skip to main content

Best Practices

SOLID Principles: Follow SOLID principles to keep our code decoupled, enabling easier refactoring as this will be important when transitioning away from React Native.


Keep It Simple: Prioritize readable and straightforward code to enhance collaboration and maintenance.


Repository Pattern: Implement the repository pattern in each feature to decouple Domain and Presentation from Data. This design ensures that changes to data structures do not impact other parts of the app.

Module: Feature:SomeFeature

domain/
├── repository/
└── SomeRepository (Interface File)
data/
├── repository/
└── SomeRepositoryImpl (Class that implements Interface)

Previews:

  • Use our custom preview settings, which is @EntainPreview, for Compose previews.
  • Create a separate composable function for the preview, and make it private.
@Composable
fun SomeButton()

@EntainPreview
@Composable
private fun SomeButtonPreview()

Declaring ViewModels in Hilt:

Declare ViewModels directly into a screen entry point when using Compose and dependency injection. Then implement a content screen to move the ViewModel data into. Previews should run against the Content Screen. We do this pattern because you can't run previews against a constructor that has a ViewModel injected into it.

Do

@Composable
fun BetslipEntryScreen(
viewModel: BetslipEntryViewModel = hiltViewModel(),
) {

BetslipEntryContent(
state = viewModel.state,
)
}

@Composable
fun BetslipEntryContent(
state :
) {
LazyColumn { … }
}

Dont

@Composable
fun BetslipEntryScreen(
viewModel: BetslipEntryViewModel = hiltViewModel(),
) {
LazyColumn { … }
}