mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
18c8417290
Summary: ## Rationale The CatalystInstance is going away after we delete the bridge. So, we should migrate away from onCatalystInstanceDestroy() to something else: invalidate(). ## Changes - Introduce the NativeModule.invalidate() cleanup hook. - Both the NativeModule and TurboModule infra now call this invalidate() method, **as opposed to** onCatalystInstanceDestroy(), to perform NativeModule cleanup. - **Is this safe?** All our NativeModules extend BaseJavaModule. BaseJavaModule.invalidate() delegates to NativeModule.onCatalystInstanceDestroy(), so NativeModules that implement onCatalystInstanceDestroy(), but not invalidate(), still have their onCatalystInstanceDestroy() method called. Changelog: [Android][Deprecated] - Deprecate NativeModule.onCatalystInstanceDestroy() for NativeModule.invalidate() Reviewed By: JoshuaGross Differential Revision: D26871001 fbshipit-source-id: e3bdfa0cf653ecbfe42791631bc6229af62f4817
60 lines
2.0 KiB
Java
60 lines
2.0 KiB
Java
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
package com.facebook.react.bridge;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import com.facebook.proguard.annotations.DoNotStrip;
|
|
|
|
/**
|
|
* A native module whose API can be provided to JS catalyst instances. {@link NativeModule}s whose
|
|
* implementation is written in Java should extend {@link BaseJavaModule} or {@link
|
|
* ReactContextBaseJavaModule}. {@link NativeModule}s whose implementation is written in C++ must
|
|
* not provide any Java code (so they can be reused on other platforms), and instead should register
|
|
* themselves using {@link CxxModuleWrapper}.
|
|
*/
|
|
@DoNotStrip
|
|
public interface NativeModule {
|
|
interface NativeMethod {
|
|
void invoke(JSInstance jsInstance, ReadableArray parameters);
|
|
|
|
String getType();
|
|
}
|
|
|
|
/**
|
|
* @return the name of this module. This will be the name used to {@code require()} this module
|
|
* from javascript.
|
|
*/
|
|
@NonNull
|
|
String getName();
|
|
|
|
/**
|
|
* This is called at the end of {@link CatalystApplicationFragment#createCatalystInstance()} after
|
|
* the CatalystInstance has been created, in order to initialize NativeModules that require the
|
|
* CatalystInstance or JS modules.
|
|
*/
|
|
void initialize();
|
|
|
|
/**
|
|
* Return true if you intend to override some other native module that was registered e.g. as part
|
|
* of a different package (such as the core one). Trying to override without returning true from
|
|
* this method is considered an error and will throw an exception during initialization. By
|
|
* default all modules return false.
|
|
*/
|
|
boolean canOverrideExistingModule();
|
|
|
|
/**
|
|
* Allow NativeModule to clean up. Called before {CatalystInstance#onHostDestroy}
|
|
*
|
|
* @deprecated use {@link #invalidate()} instead.
|
|
*/
|
|
void onCatalystInstanceDestroy();
|
|
|
|
/** Allow NativeModule to clean up. Called before {CatalystInstance#onHostDestroy} */
|
|
void invalidate();
|
|
}
|