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

[sweet][kotlin] Add basic view's callbacks support #15743

Merged

Conversation

lukmccall
Copy link
Contributor

Why

Adds a very primitive view callbacks support.

How

  • Extends a ViewManager DSL.
  • Creates a property delegate that handles callbacks.

Note

  • currently, we only support bundle as an event payload
  • you have to call invoke method on the Callback instance - it will be changed in the future

Test Plan

  • bare-expo ✅

How to create a callback

// module definition
ViewManager {
	// ...
	callbacks("onChange")
}
// view
class MyView : View {
	val onChange by callback<Bundle>()

	fun invokeOnChange(event: Bundle) {
		onChange.invoke(event)
	}
}

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Dec 29, 2021
/**
* Defines prop names that should be treated as callbacks.
*/
fun callbacks(vararg callbacks: String) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
fun callbacks(vararg callbacks: String) {
fun events(vararg callbacks: String) {

@tsapeta, I saw that you called it events on iOS. Should I rename it?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think it makes sense to call them events, as React Native does. I also just reused the component that we have in the module scope 😉
Imho the name and type "Callback" can also be used in the future for function arguments that are functions on the JS side 🤔

@lukmccall lukmccall marked this pull request as ready for review December 29, 2021 14:48
Copy link
Contributor

@bbarthec bbarthec left a comment

Choose a reason for hiding this comment

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

Awesome work 👏
Can't wait for the final result! 😁
Before merging make sure the naming is consistent with iOS platform 👀

@lukmccall lukmccall force-pushed the @lukmccall/modules-core/add-basic-view-callbacks-support branch from 72d2902 to 809546e Compare December 30, 2021 12:34
@expo-bot
Copy link
Collaborator

Hi there! 👋 I'm a bot whose goal is to ensure your contributions meet our guidelines.

I've found some issues in your pull request that should be addressed (click on them for more details) 👇

⚠️ Suggestion: Missing changelog entries


Your changes should be noted in the changelog. Read Updating Changelogs guide and consider (it's optional) adding an appropriate entry to the following changelogs:


Generated by ExpoBot 🤖 against 809546e

@lukmccall lukmccall merged commit 83e7573 into master Dec 30, 2021
@lukmccall lukmccall deleted the @lukmccall/modules-core/add-basic-view-callbacks-support branch December 30, 2021 13:18
lukmccall added a commit to software-mansion-labs/expo-maps that referenced this pull request Jan 27, 2022
Bump `expo-modules-core` to `0.7.0`:

# Changelog:

## 0.7.0 — 2022-01-26

### 🎉 New features

- Allow accessing `RCTBridge` from the modules on iOS. ([#15816](expo/expo#15816) by [@tsapeta](https://github.com/tsapeta))
- Added support for native callbacks through the view props in Sweet API on iOS. ([#15731](expo/expo#15731) by [@tsapeta](https://github.com/tsapeta))
- Added support for native callbacks through the view props in Sweet API on Android. ([#15743](expo/expo#15743) by [@lukmccall](https://github.com/lukmccall))
- The `ModuleDefinition` will use class name if the `name` component wasn't provided in Sweet API on Android. ([#15738](expo/expo#15738) by [@lukmccall](https://github.com/lukmccall))
- Added `onViewDestroys` component to the `ViewManager` in Sweet API on Android. ([#15740](expo/expo#15740) by [@lukmccall](https://github.com/lukmccall))
- Added shortened `constants` component that takes `vargs Pair<String, Any?>` as an argument in Sweet API on Android. ([#15742](expo/expo#15742) by [@lukmccall](https://github.com/lukmccall))
- Introduced the concept of chainable exceptions in Sweet API on iOS. ([#15813](expo/expo#15813) by [@tsapeta](https://github.com/tsapeta))
- Sweet function closures can throw errors on iOS. ([#15849](expo/expo#15849) by [@tsapeta](https://github.com/tsapeta))
- Add `requireNativeModule` function to replace accessing native modules from `NativeModulesProxy`. ([#15848](expo/expo#15848) by [@tsapeta](https://github.com/tsapeta))
- Implemented basic functionality of JSI host object to replace `NativeModulesProxy` on iOS. ([#15847](expo/expo#15847) by [@tsapeta](https://github.com/tsapeta))

### 🐛 Bug fixes

- It's no longer possible to directly call methods from the `ModuleDefinition` in the `ViewManagers` on Android. ([#15741](expo/expo#15741) by [@lukmccall](https://github.com/lukmccall))
- Fix compatibility with react-native 0.66. ([#15914](expo/expo#15914) by [@Kudo](https://github.com/kudo))

## 0.6.4 — 2022-01-05

### 🐛 Bug fixes

- Fix `ReactInstanceManager.onHostPause` exception from moving Android apps to background. ([#15748](expo/expo#15748) by [@Kudo](https://github.com/kudo))

## 0.6.3 — 2021-12-16

### 🐛 Bug fixes

- Fixed the deep link wasn't passed to the application if the application wasn't running when the deep link was sent. ([#15593](expo/expo#15593) by [@lukmccall](https://github.com/lukmccall))

## 0.6.2 — 2021-12-15

### 🎉 New features

- Add `onNewIntent` and `onBackPressed` support to `ReactActivityLifecycleListener`. ([#15550](expo/expo#15550) by [@Kudo](https://github.com/Kudo))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: suggestions ExpoBot has some suggestions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants