Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: custom android activities with vite #193

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

Open
NathanWalker wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from feat/vite-custom-android-activities
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,11 @@ Next, modify the activity in `App_Resources/Android/src/main/AndroidManifest.xml
android:configChanges="keyboardHidden|orientation|screenSize">
```

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

```js
::: code-group

```js [webpack]
const webpack = require('@nativescript/webpack')

module.exports = (env) => {
Expand All @@ -502,6 +504,31 @@ module.exports = (env) => {
}
```

```ts [vite]
import { defineConfig } from 'vite';
import { typescriptConfig, appComponentsPlugin } from '@nativescript/vite';

export default defineConfig(({ mode }) => {
const config = typescriptConfig({ mode });

// Register custom Android Activity and Application classes
config.plugins!.push(
appComponentsPlugin({
appComponents: [
// include any your app needs
'./src/custom-activity.android.ts',
'./src/custom-application.android.ts'
],
platform: 'android'
})
);

return config;
});
```

:::

## Implementing Kotlin and Java interfaces

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).
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /