Skip to content
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

Removed hardcoded navigator #103

Merged
merged 2 commits into from
Oct 20, 2023
Merged

Removed hardcoded navigator #103

merged 2 commits into from
Oct 20, 2023

Conversation

AndroidPoet
Copy link
Contributor

🎯 Goal

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.

The goal of this pull request is to restructure the code by moving the Compose Navigator to a ViewModel. This change is being made to make Composables independent of concrete dependencies, thereby improving scalability. This pull request addresses the need for a more modular and maintainable architecture in the codebase.

🛠 Implementation details

Describe the implementation details for this Pull Request.

In this pull request, the implementation details involve reorganizing the code to separate the Compose Navigator from concrete dependencies and placing it within a ViewModel. This change allows for greater flexibility and independence of Composables. It involves moving relevant functions, dependencies, and logic into the ViewModel. The Composables can now interact with the ViewModel instead of concrete dependencies.

✍️ Explain examples

Explain examples with code for this updates.

@HiltViewModel
class WhatsAppMessagesViewModel @Inject constructor(
  private val chatClient: ChatClient,
  private val composeNavigator: AppComposeNavigator,
  savedStateHandle: SavedStateHandle
) : ViewModel() {
  private val messageMutableUiState =
    MutableStateFlow<WhatsAppMessageUiState>(WhatsAppMessageUiState.Loading)
  val messageUiSate: StateFlow<WhatsAppMessageUiState> = messageMutableUiState

  private val channelId = savedStateHandle.get<String>("channelId")

  init {
    if (channelId != null) {
      fetchChannel(channelId = channelId)
    }
  }

  fun handleEvents(whatsAppMessageEvent: WhatsAppMessageEvent) {
    when (whatsAppMessageEvent) {
      is WhatsAppMessageEvent.NavigateUp -> composeNavigator.navigateUp()
    }
  }

Preparing a pull request for review

Ensure your change is properly formatted by running:

I have run the provided formatting command to ensure the changes are correctly formatted:

$ ./gradlew spotlessApply

Please correct any failures before requesting a review.

@AndroidPoet AndroidPoet requested a review from skydoves as a code owner October 18, 2023 15:59
@AndroidPoet
Copy link
Contributor Author

Hi @skydoves
I've made a small contribution to this project . Would you please review when you have sometime?

Thanks,
Ranbir Singh

Copy link
Member

@skydoves skydoves left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for your contribution!

@skydoves skydoves merged commit 19bf96b into GetStream:main Oct 20, 2023
1 check passed
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