Skip to content

Commit b16e361

Browse files
committed
feat: custom android activities with vite
1 parent ed7e5be commit b16e361

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

content/guide/extending-classes-and-implementing-interfaces-android.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,11 @@ Next, modify the activity in `App_Resources/Android/src/main/AndroidManifest.xml
487487
android:configChanges="keyboardHidden|orientation|screenSize">
488488
```
489489

490-
To include the new Activity in the build, make sure it's added to the `webpack.config.js` with the following:
490+
To include the new Activity in the build, make sure it's configured with the bundler you're using (webpack or vite):
491491

492-
```js
492+
::: code-group
493+
494+
```js [webpack]
493495
const webpack = require('@nativescript/webpack')
494496

495497
module.exports = (env) => {
@@ -502,6 +504,31 @@ module.exports = (env) => {
502504
}
503505
```
504506

507+
```ts [vite]
508+
import { defineConfig } from 'vite';
509+
import { typescriptConfig, appComponentsPlugin } from '@nativescript/vite';
510+
511+
export default defineConfig(({ mode }) => {
512+
const config = typescriptConfig({ mode });
513+
514+
// Register custom Android Activity and Application classes
515+
config.plugins!.push(
516+
appComponentsPlugin({
517+
appComponents: [
518+
// include any your app needs
519+
'./src/custom-activity.android.ts',
520+
'./src/custom-application.android.ts'
521+
],
522+
platform: 'android'
523+
})
524+
);
525+
526+
return config;
527+
});
528+
```
529+
530+
:::
531+
505532
## Implementing Kotlin and Java interfaces
506533

507534
The next example shows how to implement an interface in Kotlin/Java with NativeScript. The main difference between inheriting classes and implementing interfaces in NativeScript is the use of the `extend` keyword. Implement an interface is done by passing the implementation object to the interface constructor function. The syntax is identical to [Java Anonymous Classes](https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html).

0 commit comments

Comments
 (0)