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

New architecture #227

Merged
merged 5 commits into from
Feb 18, 2022
Merged

New architecture #227

merged 5 commits into from
Feb 18, 2022

Conversation

janicduplessis
Copy link
Member

@janicduplessis janicduplessis commented Dec 16, 2021

Summary

Test Plan

See updated contributing guide on how to run the example app.

Open the hooks example.

@a-eid
Copy link

a-eid commented Dec 16, 2021

for some reason, I'm not able to run the example app.

Screen Shot 2021-12-16 at 5 04 18 PM

@a-eid
Copy link

a-eid commented Dec 16, 2021

Screen Shot 2021-12-16 at 5 08 20 PM

I'm wondering why we have to use bundler & bundle ?

@janicduplessis
Copy link
Member Author

@a-eid I think you need to add sudo to the gem install bundler. It is to make sure everyone is using the same coocapods version. You can also use your globally installed version if you want by just using pod install in example/ios instead.

example/metro.config.js Outdated Show resolved Hide resolved
- (NSDictionary *)getConstants
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
if (@available(iOS 11.0, *)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is iOS 10 still supported?

Copy link
Member Author

Choose a reason for hiding this comment

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

It prob was when the code was written, but it shouldn't be now so I can clean that up.

@jacobp100
Copy link
Collaborator

This is really cool! I've not really had a chance to play with the new architecture. What's the backwards compat like?

@janicduplessis
Copy link
Member Author

@jacobp100 It should be fully backwards compatible. The new architecture is actually already used in RN core.

@janicduplessis
Copy link
Member Author

Planning to release this as a prerelease soon to confirm backwards compat is still good. The only thing that might change is require a newer version of react native, but using the new architecture will be opt in still for a while.

@billouboq
Copy link

Out of curiosity, what will be the advantages of using the new architecture with this module ? :)

@janicduplessis
Copy link
Member Author

For now I'm not using any new feature from the new architecture, but it will enable using rendering priorities which can be nice to have sync rendering when insets change and avoid flickers.

It does enable more code sharing via c++, but the main goal of this PR is just maintain current features.

:hermes_enabled => true,
:fabric_enabled => true,
:app_path => "#{__dir__}/..",
:config_file_dir => "#{__dir__}/../../..",
Copy link

Choose a reason for hiding this comment

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

Suggested change
:config_file_dir => "#{__dir__}/../../..",
:config_file_dir => "#{__dir__}/../..",

If __dir__ equal to PWD command, it will return system/user/path/react-native-xxxx/example/ios and then we should go back to times to root folder, which is react-native-xxxx

Is is correct ?

Copy link

@troZee troZee Dec 22, 2021

Choose a reason for hiding this comment

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

Ahh I see your point right now

    const codegenConfigFileDir = path.join(confifDir, dependency);

So the fileDir will be outside the library and then will point to that dependency. But the problem with that solution is that I have the other rn libraries in this dir and the codegen scans those dir, which are outside the project

As workaround I used a below command:

    "preinstall": "cp ../package.json ./codegenConfig/react-native-pager-view && cp -R ../src ./codegenConfig/react-native-pager-view",

And changed the config_file_dir

    :config_file_dir => "#{__dir__}/../codegenConfig",

Copy link
Member Author

Choose a reason for hiding this comment

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

Planning to make some improvements to config_file_dir. We want to be able to pass a direct path to a library, as well as supporting multiple values with an array.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, that seems like a better workaround than the one I have now 😅

"react-native": "0.0.0-20211215-2008-f16cbe59e",
"react-native-codegen": "^0.0.12",
"react-native-gradle-plugin": "^0.0.3",
"react-native-safe-area-context": "../"
Copy link

Choose a reason for hiding this comment

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

I was wondering, why it has been added here, but probably I found a explanation for that

  • the dep is added to package.json
  • codegen recognize it as a dep
  • using a custom path the codegen generates needed files
  • in postInstall phase this dep is. removed from node modules to avoid duplication

Could you confirm, if my above thought are correct ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep that's why, it's a hack to make codegen discover the library properly, while still using the source in the repo with the babel plugin alias to make dev simple.

Not sure if there's a better way to setup that, but for now that works.

Copy link

@sammy-SC sammy-SC left a comment

Choose a reason for hiding this comment

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

Look great! I just left few small comments. I was focusing on C++ and iOS part.

}

- (void)updateState:(facebook::react::State::Shared const &)state
oldState:(facebook::react::State::Shared const &)oldState

Choose a reason for hiding this comment

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

you can drop facebook::react as there is already using namespace on top of the file.

[self updateState];
}

- (UIView *)findNearestProvider

Choose a reason for hiding this comment

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

Would it be appropriate to log a warning in case a provider is not found?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the case that there is no provider it will use its own view to get insets from, so I think it is correct to not log anything as it will still work properly.

[self invalidateSafeAreaInsets];
}

- (void)invalidateSafeAreaInsets

Choose a reason for hiding this comment

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

Nit: often methods on iOS have suffix "ifNecessary". It suggests to a reader that there is a condition that needs to be met for the action to happen.

Maybe this method could be named "updateStateIfNecessary"?

}

auto currentStyle = yogaNode_.getStyle();
if (adjustedStyle.padding()[YGEdgeTop] != currentStyle.padding()[YGEdgeTop] ||

Choose a reason for hiding this comment

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

Could we compare adjustedStyle != currentStyle instead of comparing every value independently?

Alternatively, compare specifically only padding and margin instead of writing out all edges.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comaping paddings / margin leads to this compiler error Invalid operands to binary expression ('IdxRef<YGEdge, &YGStyle::padding_>' and 'IdxRef<YGEdge, &YGStyle::padding_>'). I assume it doesn't implement the proper compare functions in yoga.

right =
valueFromEdges(props.yogaStyle.margin(), YGEdgeRight, YGEdgeHorizontal);
}
if (std::find(edges.begin(), edges.end(), "top") != edges.end()) {

Choose a reason for hiding this comment

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

I think you could do following:

edges.find("top") != edges.end()

same result but it is easier to read.

I think free function std::find is meant to be used in templates.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think find exists for std::vector, am I missing something?

Ideally this would be a bitmask or set, but that's what is generated by codegen so I can't change it.

@janicduplessis janicduplessis marked this pull request as ready for review February 18, 2022 08:29
@janicduplessis janicduplessis merged commit 9dbb086 into main Feb 18, 2022
@janicduplessis janicduplessis deleted the new-arch-v2 branch February 18, 2022 09:13
@friederbluemle
Copy link
Contributor

Apologies for possibly using the wrong thread (couldn't find a better place).

The release notes for 3.4.0 released 3 days ago mention

Drop support for ios < 11

Isn't this a breaking change that should be done in a major version update? Reason I'm asking is because we've been getting some errors on CI during CocoaPods installation:

Specs satisfying the `react-native-safe-area-context (from `node_modules/react-native-safe-area-context`)`
dependency were found, but they required a higher minimum deployment target.

@janicduplessis
Copy link
Member Author

@friederbluemle I should have made this change as part of 4.0 in hindsight. Do you still need support for iOS < 11? In that case I would recommend staying on 3.3.x, or you can update the ios version in your podfile.

@janicduplessis
Copy link
Member Author

I decided to revert the ios min version change, it will be done in v4 instead.

@friederbluemle
Copy link
Contributor

Thank you @janicduplessis 👍

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.

None yet

7 participants