Created
April 17, 2019 06:27
-
-
Save lithin/948208ffe0e328c01a9719843645f07b to your computer and use it in GitHub Desktop.
Lazy loading native modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentWillMount = () => { | |
const { default: BiometryScanner } = require('react-native-fingerprint-scanner'); | |
BiometryScanner.isSensorAvailable() | |
.then(biometryType => { | |
return this.setState({ | |
biometryType, | |
}); | |
}) | |
.catch(() => { | |
return this.setState({ | |
biometryType: null, | |
}); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected List<ReactPackage> getPackages() { | |
List<ReactPackage> packages = new ArrayList<>(Arrays.asList( | |
new MainReactPackage(), | |
)); | |
packages.add(new LazyReactPackage() { | |
@Override | |
protected List<ModuleSpec> getNativeModules(ReactApplicationContext reactContext) { | |
return Arrays.asList( | |
ModuleSpec.nativeModuleSpec( | |
ReactNativeFingerprintScannerModule.class, | |
new Provider<NativeModule>() { | |
@Override | |
public NativeModule get() { | |
return new ReactNativeFingerprintScannerModule(reactContext); | |
} | |
})); | |
} | |
@Override | |
public ReactModuleInfoProvider getReactModuleInfoProvider() { | |
return new ReactModuleInfoProvider() { | |
@Override | |
public Map<String, ReactModuleInfo> getReactModuleInfos() { | |
Map reactModuleInfoMap = new HashMap(); | |
reactModuleInfoMap.put("ReactNativeFingerprintScanner", new ReactModuleInfo("ReactNativeFingerprintScanner", "com.hieuvp.fingerprint.ReactNativeFingerprintScannerModule", false, false, false, false, false)); | |
return reactModuleInfoMap; | |
} | |
}; | |
} | |
}); | |
// packages.add(new TurboReactPackage() { | |
// | |
// @Override | |
// public NativeModule getModule(String name, ReactApplicationContext reactContext) { | |
// switch (name) { | |
// case "ReactNativeFingerprintScanner": | |
// return new ReactNativeFingerprintScannerModule(reactContext); | |
// default: | |
// return null; | |
// | |
// } | |
// } | |
// | |
// @Override | |
// public ReactModuleInfoProvider getReactModuleInfoProvider() { | |
// return new ReactModuleInfoProvider() { | |
// @Override | |
// public Map<String, ReactModuleInfo> getReactModuleInfos() { | |
// Map reactModuleInfoMap = new HashMap(); | |
// reactModuleInfoMap.put("ReactNativeFingerprintScanner", new ReactModuleInfo("ReactNativeFingerprintScanner", "com.hieuvp.fingerprint.ReactNativeFingerprintScannerModule", false, false, false, false, false)); | |
// return reactModuleInfoMap; | |
// } | |
// }; | |
// } | |
// }); | |
return packages; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ReactModule(name="ReactNativeFingerprintScanner") | |
public class ReactNativeFingerprintScannerModule extends ReactContextBaseJavaModule | |
implements LifecycleEventListener { | |
public static final int MAX_AVAILABLE_TIMES = Integer.MAX_VALUE; | |
private final ReactApplicationContext mReactContext; | |
private FingerprintIdentify mFingerprintIdentify; | |
public ReactNativeFingerprintScannerModule(ReactApplicationContext reactContext) { | |
super(reactContext); | |
mReactContext = reactContext; | |
ReactMarker.logMarker("FINGERPRINT_START"); | |
} | |
@Override | |
public String getName() { | |
return "ReactNativeFingerprintScanner"; | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment