-
Notifications
You must be signed in to change notification settings - Fork 185
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
enhancement - allow custom reusable cells #76
Conversation
Curious, does this resolve #46? In my use cases, the ability to hide and/or remove cells is critical. How else can you perform search/filtering, etc? |
@Studio-Dude I believe it should fix #19 (and therefore #46) - I tried testing using dynamic data (from firebase) and it handled adding/deleting/updating rows fine for me. |
This is cool, I'm going to give it a spin right now! |
@mosesoak cool! it does need those 2 one-line changes in react-native.
|
@nyura123 "Major caveat: 2 changes are needed in react-native RCTRootView.m per the comments in RNReactModuleCell.h." - it is very major caveat. It makes this PR almost useless, because uses non-public API, so it could be easily broken for next versions of React Native. Is there any other way to avoid this? Btw, we could require enhancing of React Native API if we will have strong reasoning for that - you could create issue in their github or add it to https://productpains.com. If community supports it, Facebook team will done it. |
@aksonov I figured out a way around it |
…. Should be used with Item rows, not Cell's - examples in TableViewDemo
37ed8b5
to
0fd201b
Compare
@nyura123 what is the way around it? It looks like you have added an assertion to test if the required lines have been added to AppDelegate.m. Or have you found a way to do it so that those additions are not required? If so it doesn't appear to be in the PR commits yet. |
@chetstone the react-native changes are no longer needed - instead an app using this feature would need to set the bridge it wants to be used by
The problem was that I wanted the cell root views to use my global bridge I create in AppDelegate. But that bridge doesn't seem to be exposed/stored anywhere, instead you only have access to bridge.batchedBridge (for ex. through self.bridge in RNTableViewManager). If you try to pass this batchedBridge to RCTRootView initWithBridge, it will break here:
so the solution was to just manually share the bridge using a singleton. Long-term I think the react-native code above might need to be fixed by replacing the |
On Thu, Feb 25, 2016 at 4:25 PM, nyura123 [email protected] wrote:
Thanks for the reply. I don't understand everything about native bridges,
I'll give it a try. Thanks. |
@chetstone, curious if you had any luck with this? |
Yes, so far so good. I've modified the Custom Editing Example to try out sample data similar to what I need to do in my app. One thing I noticed, which may or may not be an issue is that when you add an item to the list, the other items in the list are not re-rendered. This is a potential problem because I need to display a relative time ("a few seconds ago")... It's probably OK because normally the list only needs to be re-rendered when the screen is activated, and that should happen automatically, but I'll need to do further testing in my app. And also my list is in reverse order, with the newest entry on top. When I try that, all re-render when I push the new one. Can I use shouldComponentUpdate() with this to improve rendering time? I also had a crash when clicking the Edit button when the list is empty. The problem is this line, which you recently changed:
I was going to send you a PR later today but maybe it's easier for you to just fix it. This PR was a lot of work, I appreciate it. @aksonov, what do you think? I think the idea of requiring a small change in It needs docs, and if they are too much or too confusing to put in the README, perhaps the details could be on the Wiki with a pointer from the README. Oh, one other thing I noticed that seems a little strange is the message in xcode/Chrome:
I guess it's expected but a little disconcerting to be apparently running 2 apps at once. Any possible gotchas here? |
@chetstone, thanks - yep, I'll fix the "slice" bug in the test example. Regarding "Running application" logging, you are actually running many different applications, one for each cell. An application is whatever renders into a root view, and in this case, each cell is a root view. I'm guessing in production mode, you wouldn't see this logging, but I haven't tried it. For re-rendering existing items on adding a new item, maybe explicitly passing a "time" field (or some other field to trigger rendering) in each Item would help? |
@nyura123 So AppDelegate should be changed only when user wants to use custom cells? I don't want to break compatibility with current API. Could you also change demo to use your feature? |
Yes, only if you use reactModuleForCell prop. And to clarify the prop should only be used with Items, not Cells. Cells behavior works the same as before. |
enhancement - allow custom reusable cells
I got this implemented in my project. Works great! Interestingly, performance seems to be much more responsive than ListView. I had to limit my list to 50 items with ListView to get decent performance, now I can view 500 no problem. |
@chetstone, thanks for adding the documentation - looks great to me! Great to hear it's working for you! |
Just discovered that on larger screens the Items don't use the full width of the screen. Any idea on what to look for? I don't see anything in my view styles that could be limiting the width. Here's what it looks like on a smaller screen. OK. And this on a larger screen: |
I am not 100% sure but it could be because it renders into the content view On Mon, Apr 4, 2016 at 7:01 PM, Chester Wood [email protected]
|
No issue with non-reactModuleForCell items. Explicitly setting the width parameter does help (red cell in the screen shot below). Can you suggest the easiest way to query for the proper width for the device? Note that the Inspector is pretty useless, "Inspect/Perf" buttons show up on every reactModuleForCell component. |
Setting width statically seems to work, but I can't get the cells to display at the proper width when changing orientation. In my reactModuleForCell component I added:
Console output shows that It appears that the native cells are being rendered at the right width, because native-rendered stuff like the Delete button and Disclosure indicator are correctly located on the right margin, but the width information is not being sent back to the React-native module. I think it would be preferable for it to work this way (as it seems to be done, according to the comments in the example code, for cell height). Sending width down via props is not working well. |
Maybe it's better to always have the root view take up the full width of the its parent contentView (which takes care of resizing on orientation changes). Setting autoresizingMask seems to do the trick, RNReactModuleCell.m. It still leaves space for the disclosure indicator if it's there, otherwise fills the full width.
|
That works great. Thank you! |
@nyura123 Does this support flexible cell height based on the react module's height? My cells all overlap: |
@michaelphines have you tried setting |
@nyura123 With the height property I can only set a static height, right? The problem is that the comments are of variable length in my app. For example, I can set the height to 100, but then shorter comments don't take up all the space, and longer comments overflow. This doesn't happen with Cell, but unfortunately using Cells is far too slow. Edit: sorry about the NSFW language in the previous screenshot |
(haha, looks like an interesting conversation...) |
backwards compatible, but intended to replace
<Cell>
custom cells; examples are in TableViewDemo (LargeTableExample and FirebaseExample).Fixes issues with loading large data sets (#22) and re-rendering custom cells on data changes (#19).
Usage: instead of
Cell
's, use reactModuleForCell prop: