Commit Graph

129 Commits

Author SHA1 Message Date
Nick Lockwood 4c7c365623 Fix background color glitch
Summary:Because the source of truth for backgroundColor is the shadow view, it's possible for the default RCTView backgroundColor to get overwritten by the current shadowView backgroundColor when the view is first created. This overridden value will then be used as the default whenever the background color is reset, which may not be be appropriate for other components that use RCTView.

This diff fixes the bug by ensuring that the view props (and therefore the default color) are set *before* the background color is propagated from the shadowView.

Reviewed By: furdei

Differential Revision: D3064128

fb-gh-sync-id: ac36007c094c7201a5c4fd93399dee4d3eb9a043
shipit-source-id: ac36007c094c7201a5c4fd93399dee4d3eb9a043
2016-03-17 09:40:28 -07:00
Pieter De Baets bebd9c423f Add debug tool to get shadowView from UIView
Reviewed By: nicklockwood

Differential Revision: D3058618

fb-gh-sync-id: 8e6c0ad328fa767f43438c9461b8374d1279931b
shipit-source-id: 8e6c0ad328fa767f43438c9461b8374d1279931b
2016-03-16 10:18:22 -07:00
Pieter De Baets b653d43e2e Update Dimensions when device orientation changes
Reviewed By: nicklockwood

Differential Revision: D2939877

fb-gh-sync-id: ec6161448bff34c07b93f19e1ee953657675bad5
shipit-source-id: ec6161448bff34c07b93f19e1ee953657675bad5
2016-03-15 05:49:25 -07:00
Eloy Durán 6bae7f93f5 Add suggested ‘view size’ powers to -[RCTShadowView setFrame:]
Summary:The UICollectionView example is actually my use-case, which is discussed in a
bit more detail [here](https://github.com/alloy/ReactNativeExperiments/issues/2).

----

This is useful when wrapping native iOS components that determine their
own suggested size and which would be too hard/unnecessary to replicate
in the shadow view. For instance a `UICollectionView` that after layout
will update its `contentSize`, which could be used to suggest a size to
the shadow view.

The reason for adding it to -[RCTShadowView setFrame:] is mainly so it
can be used via the existing -[RCTUIManager setFrame:forView:] API and
because it might not be a feature you want to expose too prominently.

An origin of `{ NAN, NAN }` is used as a sentinel to indicate that the
frame should be used as a size suggestion. The size portion of the rect
may contain a `NAN` to skip that dimension or a suggested value for the
dimension which will be used if no explicit styling has been assigned.

Examples:

* Without any expl
Closes https://github.com/facebook/react-native/pull/6114

Differential Revision: D2994796

Pulled By: nicklockwood

fb-gh-sync-id: 6dd3dd86a352ca7d31a0da38bc38a2859ed0a410
shipit-source-id: 6dd3dd86a352ca7d31a0da38bc38a2859ed0a410
2016-03-01 10:14:32 -08:00
Pieter De Baets f67fa82008 Add UIManager.measureInWindow to get window coordinates
Summary: When embedding in a hybrid app, we sometimes present new modal views or windows that have a different frame from the original root view. This API allows us to get coordinates in the application's window frame, which should be valid in any fullscreen view.

Reviewed By: majak

Differential Revision: D2939827

fb-gh-sync-id: 06b93cc2cb3519a25819c6efa445c779314dd673
shipit-source-id: 06b93cc2cb3519a25819c6efa445c779314dd673
2016-03-01 06:51:33 -08:00
Nick Lockwood f7df3bb78a Removed eager init of all ViewManagers on layout
Summary:The `uiBlockToAmendWithShadowViewRegistry:` is called on every single view manager, on every single layout pass. This causes all view managers to be eagerly intiialized, even if not being used.

In practice very few modules actually use this method, so by checking if the method is implemented before calling it, we can eliminate most of this work.

(Hopefully in future we can get ride of this method altogether, but right now it's integral to the way that text layout is implemented).

Reviewed By: majak, javache

Differential Revision: D2982181

fb-gh-sync-id: 818d0aac61197df89263c919c2c80a003e293ac5
shipit-source-id: 818d0aac61197df89263c919c2c80a003e293ac5
2016-02-26 08:18:34 -08:00
Pieter De Baets f51c16b270 Avoid dirtying layout when frame doesn't change
Reviewed By: nicklockwood

Differential Revision: D2939782

fb-gh-sync-id: e2346f053e9594e5d24d1e73d493a34446fb228c
shipit-source-id: e2346f053e9594e5d24d1e73d493a34446fb228c
2016-02-25 09:39:29 -08:00
Nick Lockwood 4b4455f827 Removed 'screen' option from snapshot API
Summary:Unfortunately the 'screen' option in the `UIManager.takeSnapshot` API appears to work only on the iOS simulator, not on an actual device.

This diff removes the 'screen' option until a solution can be found that works on the device.

(Taking a snapshot of the window still works fine - it just won't include the status bar, etc.)

Reviewed By: javache

Differential Revision: D2971091

fb-gh-sync-id: 026b9d4eb2f59f686f58c18a16381ff325df612b
shipit-source-id: 026b9d4eb2f59f686f58c18a16381ff325df612b
2016-02-24 09:06:31 -08:00
Nick Lockwood ac12f98689 Added support for taking snapshots of the screen, window or individual views
Summary:This adds a `takeSnapshot` method to UIManager that can be used to capture screenshots as an image.

The takeSnapshot method accepts either 'screen', 'window' or a view ref as an argument.

You can also specify the size, format and quality of the captured image.

I've added an example of capturing a screenshot at UIExplorer > Snapshot / Screenshot.
I've also added an example of sharing a screenshot to the UIExplorer > ActionSheetIOS demo.

Reviewed By: javache

Differential Revision: D2958351

fb-gh-sync-id: d2eb93fea3297ec5aaa312854dd6add724a7f4f8
shipit-source-id: d2eb93fea3297ec5aaa312854dd6add724a7f4f8
2016-02-23 02:26:33 -08:00
Pieter De Baets 7964d80759 Replace ModalFullscreenView constants by Dimensions
Reviewed By: jingc

Differential Revision: D2954172

fb-gh-sync-id: 8b2f68d13632de25830678ddc32a36c239970427
shipit-source-id: 8b2f68d13632de25830678ddc32a36c239970427
2016-02-22 05:29:32 -08:00
Pieter De Baets bb5a6be9dd Only execute update block once
Summary:
We were executing all the updateBlocks for every frame that was updated in the UI flush. This would quickly give you an explosive number of block calls when loading complex views.

This update block is only really used by text to propagate padding, even though the actual insets are mostly just 0.

public

Reviewed By: nicklockwood

Differential Revision: D2848968

fb-gh-sync-id: e43c529c2bb9729e2b779bf4abefeed58775cc2e
2016-02-01 07:51:35 -08:00
Nick Lockwood 17df595e32 Implement Android's dispatchViewManagerCommand interface on iOS
Summary:
public
Android implement ViewManager methods via a dispatch method on UIManager, whereas iOS implements them by exposing the methods on the view manager modules directly.

This diff polyfills Android's implementation on top of the iOS implementation, allowing the same JS API to be used for both.

Reviewed By: javache

Differential Revision: D2803020

fb-gh-sync-id: 0da0544e593dc936467d16ce957a77f7ca41355b
2016-01-06 05:58:37 -08:00
Nick Lockwood d7ad393f22 Fix unused argument warnings
Reviewed By: milend

Differential Revision: D2795407

fb-gh-sync-id: 83f5cc10b115eef3becb4ebab56b366f1a12a3ad
2015-12-30 14:16:29 -08:00
John Ku c34ef25ec5 fix incorrect count for layoutAnimation callback
Summary:
fixes #3106
Having -1 would trigger callback one frame early causing it to be ignored on the next frame.
Closes https://github.com/facebook/react-native/pull/3190

Reviewed By: svcscm

Differential Revision: D2783700

Pulled By: mkonicek

fb-gh-sync-id: 02070f70915055aec3b1543a8d553f2680438611
2015-12-23 10:07:51 -08:00
Nick Lockwood 9f48c004ba Added setChildren() function
Summary:
public
Most of the time - especially during app startup - when we call UIManager.manageChildren(), we are actually just adding the first set of children to a newly created view.

This case is already optimized for in the JS code, by memoizing index arrays at various sizes, but this is not especially efficient since it is still sending an array of indices with each call that could be easily inferred on the native side instead.

I've added a hybrid native/JS optimization that improves the performance for this case. It's not a huge win in terms of time saved, but benchmarks show improvements in the ~1% range for several of the app startup metrics.

Reviewed By: tadeuzagallo

Differential Revision: D2757388

fb-gh-sync-id: 74f0cdbba93af2c04d69b192a8c2cc5cf429fa09
2015-12-15 06:56:31 -08:00
Nick Lockwood f7edcda5d7 Deprecated RCTDidCreateNativeModules notification
Summary:
public

Thanks to the new lazy initialization system for modules, `RCTDidCreateNativeModules` no longer does what the name implies.

Previously, `RCTDidCreateNativeModules` was fired after all native modules had been initialized. Now, it simply fires each time the bridge is reloaded. Modules are created on demand when they are needed, so most of the assumptions about when `RCTDidCreateNativeModules` will fire are now incorrect.

This diff deprecates `RCTDidCreateNativeModules`, and adds a new notification, `RCTDidInitializeModuleNotification`, which fires each time a module a new module is instantiated.

If you need to access a module at any time you can just call `-[bridge moduleForClass:]` and the module will be instantiated on demand. If you want to access a module *only* after it has already been instantiated, you can use the `RCTDidInitializeModuleNotification` notification.

Reviewed By: tadeuzagallo

Differential Revision: D2755036

fb-gh-sync-id: 25bab6d5eb6fcd35d43125ac45908035eea01487
2015-12-15 05:43:33 -08:00
Martin Kralik a86171a482 exposed a way to trigger layout on the uimanager
Summary:
A component can be backed by native "node" that can change its internal state, which would result in a new UI after the next layout. Since js has no way of knowing that this has happened it wouldn't trigger a layout if nothing in js world has changed. Therefore we need a way how to trigger layout from native code.

This diff does it by adding methods `layoutIfNeeded` on the uimanager and `isBatchActive` on the bridge.
When `layoutIfNeeded` is called it checks whether a batch is in progress. If it is we do nothing, since at it's end layout happens. If a batch is not in progress we immidiately do layout.

I went with the easiest way how to implement this - `isBatchActive` is a public method on the bridge. It's not ideal, but consistent with other methods for modules.
public

Reviewed By: jspahrsummers, nicklockwood

Differential Revision: D2748896

fb-gh-sync-id: f3664c4af980d40a463b538e069b26c9ebad6300
2015-12-11 06:59:30 -08:00
Nick Lockwood 88ac40666c Replaced RegExp method parser with recursive descent
Summary:
public

This diff replaces the RegEx module method parser with a handwritten recursive descent parser that's faster and easier to maintain.

The new parser is ~8 times faster when tested on the UIManager.managerChildren() method, and uses ~1/10 as much RAM.

The new parser also supports lightweight generics, and is more tolerant of white space.

(This means that you now can – and should – use types like `NSArray<NSString *> *` for your exported properties and method arguments, instead of `NSStringArray`).

Reviewed By: jspahrsummers

Differential Revision: D2736636

fb-gh-sync-id: f6a11431935fa8acc8ac36f3471032ec9a1c8490
2015-12-10 10:12:29 -08:00
Dan Witte 70f0dfc0e6 revert D2707930
Reviewed By: fkgozali

Differential Revision: D2720828

fb-gh-sync-id: 53113fb33150b42a7b597a7dfd04bb9885def029
2015-12-03 18:29:28 -08:00
Nick Lockwood 9a47ca1cc9 Added addChildren() function as a more-optimal replacement for manageChildren for common use cases.
Reviewed By: jspahrsummers

Differential Revision: D2707930

fb-gh-sync-id: c44219bf9af943cad5b57f370656c1bcac732cd9
2015-12-03 11:34:27 -08:00
Justin Spahr-Summers c25c98c00c Flush UI blocks as soon as they're accumulated
Summary:
public

Currently, we wait to invoke `-flushUIBlocks` until the JavaScript batch to native has completed. This means we may be waiting an unnecessarily long time to perform view hierarchy changes and prop changes.

By instead invoking this after each chunk of enqueued UI blocks, we can perform some updates more eagerly, increasing our utilization of the main thread while splitting up the amount of time we spend running upon it.

This shouldn't affect layout, which is still tied to `-batchDidComplete`, so any visual inconsistencies should be limited to prop changes, which seems acceptable for the dramatic improvement in performance.

Reviewed By: javache

Differential Revision: D2658552

fb-gh-sync-id: 6d4560e21d7da1b02d2f30d1860d60735f11c4b5
2015-12-02 06:03:27 -08:00
Martin Kralik be285c43d1 use didSetProps instead of updateLayout
Summary: There is no point in using `updateLayout` when we have `didSetProps`.
The only a bit risky part is calling `dirtyLayout` in `setFrame:forView:` instead of `updateLayout`,
but since setting frame shouldn't really change border/margin/padding it should be ok.

Depends on D2699512.

public

Reviewed By: nicklockwood

Differential Revision: D2700012

fb-gh-sync-id: a7c33b3b4e3ddc195bebebb8b03934131af016fb
2015-11-27 04:03:48 -08:00
Nick Lockwood 060664fd3d Refactored module access to allow for lazy loading
Summary: public

The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed.

This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead.

The rules are now as follows:

* Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created
* Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but  `constantsToExport:` will still be called on the main thread.
* All other modules will be initialized lazily when a method is first called on them.

These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily.

I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results:

Out of the 65 modules included in UIExplorer:

* 16 are initialized on the main thread when the bridge is created
* A further 8 are initialized when the config is exported to JS
* The remaining 41 will be initialized lazily on-demand

Reviewed By: jspahrsummers

Differential Revision: D2677695

fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
2015-11-25 04:49:45 -08:00
Pieter De Baets 38db6fa465 Remove scrollview support from UIManager, remove mainScrollView(delegate)
Reviewed By: nicklockwood

Differential Revision: D2692749

fb-gh-sync-id: 48975d2f09f3b2902dfa2e56ff9d34257b2395bc
2015-11-25 04:12:34 -08:00
Nick Lockwood ca20d710fc Removed duplicate UIManager constants
Summary: public

We were calling constantsToExport twice for every ViewManager, and including two copies of the values in __fbBatchedBridgeConfig. This diff removes the copy from UIManager and then puts it back on the JS side.

Reviewed By: tadeuzagallo

Differential Revision: D2665625

fb-gh-sync-id: 147ec4bfb404835e3875964476ba233d619c28aa
2015-11-18 04:47:27 -08:00
Justin Spahr-Summers 0491142702 Invoke -reactBridgeDidFinishTransaction per-batch, not per-flush
Reviewed By: tadeuzagallo, majak

Differential Revision: D2663382

fb-gh-sync-id: f3bd77e0ec8fd4129657fc1c23cc542cf7f0c223
2015-11-17 10:22:26 -08:00
Pieter De Baets c043c68e7e Return viewsWithNewFrame instead of passing it around
Reviewed By: nicklockwood

Differential Revision: D2663281

fb-gh-sync-id: 6218c2ff68f7e4d8132ef1f95fb22f5007434319
2015-11-17 06:37:31 -08:00
Nick Lockwood b7f5062128 Fixed nil insert crash in shadowViewRegistry
Summary: public

In iOS < 9, inserting a nil object into NSMutableDictionary crashes. It is valid for come components to return a nil shadowView (e.g. ART nodes), and this was crashing on iOS 8.

Reviewed By: jspahrsummers

Differential Revision: D2658309

fb-gh-sync-id: 7abf9273708cc03c3b6307b69ba11c016b471fbe
2015-11-16 09:19:24 -08:00
Nick Lockwood fa0b45c58b Replaced RCTSparseArray with NSDictionary
Reviewed By: jspahrsummers

Differential Revision: D2651920

fb-gh-sync-id: 953e2ea33abfc7a3a553da95b13e9ab2bccc5a1c
2015-11-14 10:28:28 -08:00
Justin Spahr-Summers 0276dde612 Increase priority of UIManager's shadowQueue
Summary: This queue processes layout and user interface updates, so it should have as high a quality-of-service/priority as possible.

public

Reviewed By: javache

Differential Revision: D2641837

fb-gh-sync-id: 934686f7969b43101af183148d67ff7be4bdf660
2015-11-12 07:05:19 -08:00
Pieter De Baets be9cd6c9cf Don't traverse view trees that are not managed by react-native-github
Reviewed By: tadeuzagallo

Differential Revision: D2641753

fb-gh-sync-id: 924df6c4142ad4a467003d0039a0d7f843d9b63c
2015-11-11 08:15:35 -08:00
Tadeu Zagallo e5b843834d Rename RCTProfile(Begin|End)Event
Summary: public

Rename it to `RCT_PROFILE_(BEGIN|END)_EVENT` to make it clearer that it's a macro,
since it has special behaviours.

Reviewed By: jspahrsummers

Differential Revision: D2631542

fb-gh-sync-id: 629c139462c4aa3582f719b14482017d13676e33
2015-11-09 08:43:29 -08:00
Tadeu Zagallo de1c0169fc Clean up unnecessary profile events
Summary: public

There were some old markers that are now automatically inject and now are no longer necessary (+ one that was missing an end call :( ))

Reviewed By: javache

Differential Revision: D2625901

fb-gh-sync-id: 4c4c9d6b4e8e2b4bdb9c64fde01000b0ca2e9f47
2015-11-06 06:55:30 -08:00
Pieter De Baets 31b5b0ac01 Create RCTFatal for reporting fatal React events
Summary: public

Add RCTFatal for reporting fatal runtime conditions. This centralizes failure handling to one function and allows you to customize how they should be handled. RCTFatal will be logged to the console and as a redbox and will also be triggered by fatal exceptions coming from RCTExceptionsManager.

Note that there is no RCTLogFatal, since just logging the fatal condition does not allow us to handle it consistently.

Reviewed By: nicklockwood

Differential Revision: D2615490

fb-gh-sync-id: 7d8e134419e10a8fb549297054ad955db3f6bee0
2015-11-05 12:51:27 -08:00
Nick Lockwood c5b990f65f Added lightweight generic annotations
Summary: public

Added lightweight genarics annotations to make the code more readable and help the compiler catch bugs.

Fixed some type bugs and improved bridge validation in a few places.

Reviewed By: javache

Differential Revision: D2600189

fb-gh-sync-id: f81e22f2cdc107bf8d0b15deec6d5b83aacc5b56
2015-11-03 14:49:30 -08:00
Pawel Sienkowski 1efb9dc063 Remove invalid assertion from RCTUIManager
Reviewed By: javache

Differential Revision: D2606613

fb-gh-sync-id: e8d9bcf5d23b720230de4904cab577f097010150
2015-11-03 09:07:30 -08:00
Tadeu Zagallo 1c9a74bbd1 Kill UIManager lock
Summary: public

The UIManager had a lock around the enqueued ui blocks, but now all the operations
should happen on the shadow thread, so I added assertions to it and removed the
locks.

Reviewed By: nicklockwood

Differential Revision: D2605760

fb-gh-sync-id: e1bc649f759502e7e9fd059932e0cba38dba05bf
2015-11-03 03:57:27 -08:00
Pawel Sienkowski 6faface188 RCTUIManager's setFrame:forView: fix - add support for Modal
Reviewed By: javache

Differential Revision: D2585415

fb-gh-sync-id: f367cf5353593363357dd86ec959acb1676cba9b
2015-10-27 09:22:28 -07:00
Martin Kralik f916ec26a6 removed unnecessary dispatches to main queue
Summary: There is no point in dispatching to main thread if there is nothing to do there.
This place gets called basically any time a repeating js timer fires, which doesn't imply UI changes (although usually that's why people setup timers).
Combined with previous diffs that makes us not generate empty blocks (nil instead), this could be minor perf win in some rare cases.

This also changes semantic of `reactBridgeDidFinishTransaction` call a bit. Previously it was done no matter if UI has changed or not.
I think it should be safe, since seems like callees really care only about views being laid out.

Depends on D2571166. (not strictly speaking)

public

Reviewed By: jspahrsummers, nicklockwood

Differential Revision: D2571188

fb-gh-sync-id: 02d52e4615475072c3c27226e67c431a667ec990
2015-10-27 05:09:45 -07:00
Martin Kralik 28f5af0c39 nil instead of empty `RCTViewManagerUIBlock` blocks
Summary: Same as in previous diffs. Gets us into a better place to know if we really have UI updates and it's marginally more efficient.

Depends on D2571143. (not really)

public

Reviewed By: nicklockwood

Differential Revision: D2571166

fb-gh-sync-id: e8f34521ec2e12156a49f1cd655e92df1db34fca
2015-10-27 05:09:39 -07:00
Martin Kralik af70d05838 moved `reactBridgeDidFinishTransaction` calls
Summary: Previously `_bridgeTransactionListeners` were informed about `reactBridgeDidFinishTransaction` inside of one of the UI blocks.
That seems pretty arbitrary, doesn't really mean a "transaction" is really over (assuming transaction means all UI updates) and even when that block does nothing we still need to call these listeners, since there could be other UI blocks generated somewhere else!
So I've moved this call to a place that seemed better (=after all UI blocks are done), since all listeners are interested in knowing when layout has happened.

public

Reviewed By: nicklockwood

Differential Revision: D2571122

fb-gh-sync-id: 62be03ebc4353d6f6318c9765079b87b07483be2
2015-10-27 05:09:25 -07:00
Pawel Sienkowski 576f5d79af Introduction of RCTRootViewDelegate
Reviewed By: adamjernst

Differential Revision: D2532327

fb-gh-sync-id: 0d018a6c2842f8021718fb7387ee6acb5d894645
2015-10-26 15:41:36 -07:00
Pawel Sienkowski 46803f0617 Size flexibility modes for RCTRootView
Reviewed By: javache

Differential Revision: D2526355

fb-gh-sync-id: 095a43bc01f883fdfdad3a086a35682c20c05597
2015-10-26 15:41:29 -07:00
Ryan Olson 1091ecd8e0 Respect destination vaules in LayoutAnimation create
Reviewed By: nicklockwood

Differential Revision: D2544389

fb-gh-sync-id: 9e6abdbd1f500578369e5f2c3e34d7f5ef047f5e
2015-10-16 08:39:22 -07:00
James Ide cb8b656a82 Only handle accessibility notifications from the correct RCTAccessibilityManager
Summary: When you reload and create a new bridge, one of the things that happens during setup is that the RCTAccessibilityManager fires a notification. The old bridge would receive this notification from the new bridge's RCTAccessibilityManager, which we don't want, especially because the two are running on different shadow queues.

I believe this led to a gnarly crash in NSConcreteTextStorage because RCTMeasure in RCTShadowText.m was getting called for the old RCTText (getting destroyed) from a notification fired from the new shadow queue. The fix is for the UIManager to handle notifications only from its bridge's RCTAccessibilityManager. See #2001 for the kinds of crashes we were seeing.
Closes https://github.com/facebook/react-native/pull/3279

Reviewed By: @​svcscm

Differential Revision: D2521652

Pulled By: @nicklockwood

fb-gh-sync-id: a4ffe3ef8304667727e573e2a2e8b716e1d2f3e1
2015-10-08 04:00:41 -07:00
Nick Lockwood bb5522582d Fixed layout animation crash 2015-09-04 05:34:46 -08:00
Nick Lockwood aa62a5e4e0 Send layout events on shadow queue
Summary:
We currently wait until after views have been updated on the main thread before sending layout events. This means that any code that relies on those events to update the UI will lag the atual layout by at least one frame.

This changes the RCTUIManager to send the event immediately after layout has occured on the shadow thread. This noticably improves the respinsiveness of the layout example in UIExplorer, which now updates the dimension labels immediately instead of waiting until after the layout animation has completed.
2015-09-03 03:42:26 -08:00
Nick Lockwood 848839858b Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.

This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.

The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.

  RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)

If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 06:11:24 -08:00
Matt Mahoney 36c1064033 [rn] Pass props when creating a view in RCTViewManager 2015-08-25 08:08:17 -08:00
Nick Lockwood 88e0bbc469 Ran Convert > To Modern Objective C Syntax 2015-08-25 01:08:49 -08:00