0.6.20 • Published 1 month ago

@bittingz/expo-widgets v0.6.20

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

expo-widgets

An expo module that allows you to make native widgets in iOS and android.

Installation

npx expo install @bittingz/expo-widgets

Setup

See the example project for more clarity. You can omit the android or ios folders and setup if you only wish to support one platform.

  1. Create a folder where you want to store your widget files.
  2. In your plugins array (app.config.{js/ts} add:
[
    "@bittingz/expo-widgets",
    {
        ios: {
            src: "./src/my/path/to/ios/widgets/folder",
            devTeamId: "your apple dev team ID",
            mode: "production",                        
            moduleDependencies: [],
            useLiveActivities: false,
            frequentUpdates: false,
        },
        android: {
            src: "./src/my/path/to/android/widgets/folder",
            resourceName: "@xml/my_widget_info",
            distPlaceholder: "optional.placeholder"
        }                      
    }
],
  1. Within your iOS widget folder create a Module.swift file, Widget Bundle, Assets.xcassets, and Widget swift files.
  2. Your android folder should mimic android studio setup, so it has two subfolder paths: /android/main/java/package_name and /android/res/.... The package_name is currently being worked on for adjusting the name. Inside you place your widget.kt files. The res folder should contain your assets, the same as in android studio.
  3. If you have any swift files you need to use within Module.swift, simply add them to the moduleDependencies array in your app.config. This is particularly useful for data models between the module and widget.
  4. To share data between your app and widgets you can use a variety of methods, but the easiest way is to use UserPreferences. This plugin automatically handles it for you, so all you have to do is make sure to use a suiteName with the correct format. See the example project.
  5. If you want to use custom fonts in your widget, use my expo-native-fonts package. See the example project for usage.
  6. For android, set resourceName to your file name in /res/xml/***_info.xml
  7. For android apps which require multiple distributions with different package names you can use distPlaceholder which will replace all instances of the provided placeholder in widget source files with your app.config.(json/ts/js). So if your source files include "package com.company.app" and "import com.company.app" and you have two distributions (com.company.app for prod and dev.company.app for dev) then setting distPlaceholder to com.company.app will replace all package and import references to the correct distribution each build. You can omit this field if it's not relevant to you. iOS requires no configuration for multiple distribution apps.

Overriding xcode options

If you need to override xcode options (such as handling a swift version mismatch) you can add the following:

xcode: {
    configOverrides: {
        SWIFT_VERSION: '5.0',
    },                        
},

The configOverrides properties are the xcodeproj values and must match case exactly.

Running the example project

cd example
npm run prebuild 
npx expo run:ios

Troubleshooting Android

If you use R in your widget kotlin file to get layouts, you may get an unresolved reference error for R. In this case, simply add "package your.appconfig.packageid.R", delete your android folder and rebuild.

Need Custom Fonts?

Give my other expo module a try. You'll need to put the fonts config before the widgets config.

Thanks!

A huge thanks to gashimo for a great baseline to start from.

0.6.20

1 month ago

0.6.19

1 month ago

0.6.18

1 month ago

0.6.17

1 month ago

0.6.14

1 month ago

0.6.16

1 month ago

0.6.15

1 month ago

0.6.12

1 month ago

0.6.11

1 month ago

0.6.13

1 month ago

0.6.10

1 month ago

0.6.7

1 month ago

0.6.6

1 month ago

0.6.9

1 month ago

0.6.8

1 month ago

0.6.3

1 month ago

0.6.2

1 month ago

0.6.5

1 month ago

0.6.4

1 month ago

0.6.1

2 months ago

0.6.0

2 months ago

0.5.55

3 months ago

0.5.54

3 months ago

0.5.53

7 months ago

0.5.52

7 months ago

0.5.51

7 months ago

0.5.50

7 months ago

0.5.49

7 months ago

0.5.48

7 months ago

0.5.47

7 months ago

0.5.46

7 months ago

0.5.45

7 months ago

0.5.44

8 months ago

0.5.43

8 months ago

0.5.42

8 months ago

0.5.41

8 months ago

0.5.40

8 months ago

0.5.39

8 months ago

0.5.38

8 months ago

0.5.37

8 months ago

0.5.36

8 months ago

0.5.35

8 months ago

0.5.34

8 months ago

0.5.33

8 months ago

0.5.32

8 months ago

0.5.31

8 months ago

0.5.30

9 months ago

0.5.29

9 months ago

0.5.28

9 months ago

0.5.27

9 months ago

0.5.26

9 months ago

0.5.25

9 months ago

0.5.24

9 months ago

0.5.23

9 months ago

0.5.22

9 months ago

0.5.21

9 months ago

0.5.20

9 months ago

0.5.19

9 months ago

0.5.18

9 months ago

0.5.17

9 months ago

0.5.16

9 months ago

0.5.15

9 months ago

0.5.14

9 months ago

0.5.13

9 months ago

0.5.12

9 months ago

0.5.11

9 months ago

0.5.10

9 months ago

0.5.9

9 months ago

0.5.8

9 months ago

0.5.7

9 months ago

0.5.6

9 months ago

0.5.5

9 months ago

0.5.4

10 months ago

0.5.3

10 months ago

0.5.2

10 months ago

0.5.1

10 months ago

0.5.0

10 months ago

0.4.3

10 months ago

0.4.2

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago